PHP - Storing/retrieving Array
Hello all,
I'm currently working on a project and it is the first time I have had to store/retrieve an array with PHP and MySQL. Basically its a website that has a list of discounts/coupons on it. People can register and submit their discounts and such. I am storing an array for who is eligible for the discount, as well as which categories the discount falls under. I did some googling and there seems to be tons of thoughts on the best way to do this. Some say to use implode/explode, some say to serialize/unserialize, I was just wondering if there is a common, concrete way to do this? I will need to be able to search the array for its contents. So if children are eligible for the discount, I need to be able to store that in a database, retrieve it later, and search it for only "Children" so I can display the discounts available only to children. If someone could please advise the best way to do this and post some examples, it would be greatly appreciated. I learn best with examples that are explained properly. Similar TutorialsHi, just a very simple question: I have an array as follows: $langList = array('English', 'French', 'German', 'Dutch'); What's the easiest way to store this array in an external file, so that multiple php scripts can access its contents? And what is then the php line I need to retrieve the array from the external file? Thanks! I need some help with this. A user fills out a form, one of the fields is a zip code field. I need to retrieve that value from MySQL store as a session var and set that value as a variable to use with a weather display API. The ID is being stored from the form page. Here is what I have so far, after the values are submitted into the DB. <?php session_start(); $con = mysql_connect("localhost","peter","abc123"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("my_db", $con); $result = mysql_query("SELECT * FROM Profile WHERE id='{$_SESSION['id']}"); while ($row = mysql_fetch_assoc($result)) { $_SESSION['id'] = $row['id']; $_SESSION['zip'] = $row['zip']; } mysql_close($con); ?> and then for the weather API, I need to set the stored variable to something $zip = 'stored zip code value'; I am working on a kind of CMS for my own website which no one else will be using but me as a way of improving my php skills, and am having problems with retrieving data from the database that holds both text and php code. I have searched the web and found that i should be using eval() for the code to be executed before it is send to the browser but cannot get it to work and can't find my mistake(s). the php code will always be the same, and is supposed to retrieve the id number of a page to use in a link (and works fine when tested by loading the code directly without retrieving it from the database) this is an example of data stored in the database Code: [Select] The <a href="page_builder.php?id=<?php echo $page->id('mines_DwarvenMines') ?>">Dwarven Mines</a> have a great selection of Ores,... Of course when I leave it like this, hovering over the link in my page will show exactly that and lead to nowhere Code: [Select] localhost/page_builder.php?id=<?php echo $page->id('mines_DwarvenMines') ?> Most of these links appear in tips given at the end of the page and are processed as followed Code: [Select] $questtips = $quest->getQuestTips(); $tips = ""; if ($questtips == "none") { $tips = "/"; } else { foreach($questtips as $tip) { $tips .= "<li>"; $tips .= $tip->getTip(); $tips .= "</li>"; } } and finally put on screen by the presentation layer as followed Code: [Select] <h2>Tips & Extra Info</h2> <div class="tipsList"> <ul> <?php echo $tips ?> </ul> </div> I have tried all sorts to get the code to be executed when retrieved from the database before being send to the browser so that this particular link would say "localhost/page_builder.php?id=57" but I cannot get it to work, though I suspect it is fairly easy. I suspect I would have to store the data in a different format in the database? And how exactly do I use the eval() function in my case? Could someone please adjust my code so that it does work? Thanks As part of a form submission, I have several textboxes The textboxes have an array name such as text[]. I'm sending the textbox values via http request. Sending an element value via http request is usually be done using document.getElementById, assigning the elements ID to a var and posting the var name . Then accessing the value using $_POST. However I'm sending an array of string values. How do I access the array using $_POST? Any help appreciated. Hi All, small question here. I was just playing around with a small script I made to obtain an ip-address, remove the dots and than glue the parts together. Not for any use but for practice. But I am having difficulties to accessing the array values. But maybe that because its the first time i am using explode() and print_r. If someone has a spare minute I would be pleased to be enlightened. <?php $ip=$_SERVER['REMOTE_ADDR']; echo $ip.'<br />'; $cleaned_ip = substr($ip,0,6); echo $cleaned_ip.'<br />'; $cleaned_ip2 = print_r(explode('.', $ip, 6)).'<br />'; // this is the point where I dont know how to get the array values. // echo $cleaned_ip2[0].[1].[2]; that doesnt work. ;( ?> I use Popshops Datafeed API and cant figure out an issue im having with an array. I'm trying to retrieve a category name from an array for the current page. Here is the array code which is in the index.php file. $categories = array(); $categories[] = array( 'name' => 'page name', 'search_options' => array( 'keywords' => 'page keyword' ) ); $categories[] = array( 'name' => 'page name', 'search_options' => array( 'keywords' => 'page keyword' ) ); $categories[] = array( 'name' => 'page name', 'search_options' => array( 'keywords' => 'page keyword' ) ); This is how the script calls the current page keyword. <?php echo ucwords($_REQUEST[$popshops->nameSpace.'keywords']) ?> The code above works fine, so I thought all I had to do was change the 'keywords' to 'name' to get what I was looking for. But that does not seem to work? <?php echo ucwords($_REQUEST[$popshops->nameSpace.'name']) ?> I've tried as much as my limited php knowledge can take me, so now I need some advice. Here is the function in the popshops.php file they use to pull the page name out for the links in the navigation, but I just want to know how to retrieve just the category name for the current page, nothing else. function customCategoryLink($category) { $url = $this->baseURL($this->params); if (isset($category['search_options']) && sizeOf($category['search_options']) > 0) { foreach($category['search_options'] as $key => $value) { $url = $this->addParameter($url,$key,$value); } } else { $url = $this->addParameter($url,'keywords',$category['name']); } $url = str_replace('?&','?',$url); return '<a href="'.$url.'">'.$category['name'].'</a>'; } Thanks in advanced! Code: [Select] $a = $landSellCheck[0]; echo("<p>a: $a"); $a = $landSellCheck[1]; echo("<p>a: $a"); $a = $landSellCheck[2]; echo("<p>a: $a"); $i = 0; $landSellCheck = $landSellCheck[$i]; echo("<p>b: (0): $landSellCheck"); $i = 1; $landSellCheck = $landSellCheck[$i]; echo("<p>b: (1): $landSellCheck"); $i = 2; $landSellCheck = $landSellCheck[$i]; echo("<p>b: (2): $landSellCheck"); As can be seen from the output below when I echo my array by manually inserting the index number, it works fine as it should. If I set the index number as a variable and echo it, it works for index value 0, for index value 1 is gives 'a' somehow (no idea where that comes from) and for index value 2 it is empty. What am I doing wrong? Output is: a: landSellConfirm7 a: landSellConfirm6 a: landSellConfirm1 b: (0): landSellConfirm7 b: (1): a b: (2): PLEASE HELP! I need help I am a new php user, and am trying to understand how to read a .txt file into an array then to retrieve the index of the array at will. Code: [Select] <?php //echo $myfile = fopen("ArrayTestFile.txt", "r") . "File exists: " or die("File does not exist or you lack permission to open it! "); //echo "The contents of the file is " . file_get_contents("ArrayTestFile.txt") . "<br />"; $fh = fopen("ArrayTestFile.txt", 'r+') or die("Failure"); $array = array(); //creation of array $num = fgets($fh);// recursive call variable $num fgets(.txt line) for ($i = 0; $i <= 5; $i++) //for loop loads first 5 of .txt { $array["i"] = $num; //loads each line of .txt into the array at the loops index. echo "Line " . $i . " of the array is " . $array["i"]; // displays the contents of the array in a print message } ?> Thank you. MOD EDIT: code tags added. Script:
<?php // For example, the entries in the table. $entry1 = "text1"; $entry2 = "text2"; $entry3 = "text3"; // For example, the ID numbers in the table. $value1 = "140"; $value2 = "141"; $value3 = "142"; echo "<form method='POST' action='" . $_SERVER['PHP_SELF'] . "'>"; echo "<input type='checkbox' name='hashtag_modify_checkbox[]' value='" . $value1 . "' />"; echo "Modify"; echo "<input type='text' name='hashtag_name[]' value='" . $entry1 . "' />"; echo "<input type='checkbox' name='hashtag_modify_checkbox[]' value='" . $value2 . "' />"; echo "Modify"; echo "<input type='text' name='hashtag_name[]' value='" . $entry2 . "' />"; echo "<input type='checkbox' name='hashtag_modify_checkbox[]' value='" . $value3 . "' />"; echo "Modify"; echo "<input type='text' name='hashtag_name[]' value='" . $entry3 . "' />"; echo "<input type='submit' name='submit' />"; echo "</form>"; // Here, only store those hashtag names where the "modify" checkbox is checked. ?>This is used for the admin panel. It is a form where the input fields hold the text ("hashtags") already inside of them. Basically, one would have to check the "modify checkbox" to modify a hashtag, then only the modified hashtags should get stored into an array. How to have those hashtags stored in the array with the checked checkbox as the factor? The suggestions are much appreciated. Edited by glassfish, 23 October 2014 - 10:06 AM. Hi, I'm having problems retrieving the values from a form posting without getting a warning My form records playername, hours played and minutes played Code: [Select] <li id="input1" style="margin-bottom:4px;" class="clonedInput"> Name: <select name="player[1][userid]" id="player[1][userid]" class="playerInput" style="width: 7em;" > <option value=""></option> <?php while($row = mysql_fetch_array($sql)) { echo '<option value="'.stripslashes($row['userid']).'">'.stripslashes($row['name']).'</option>'; } mysql_data_seek($sql,0); ?> </select> <select name="player[1][hours]" id="player[1][hours]"> <option value="">Hours</option> <option value=""></option> <?php for($x = 0; $x <= 23; $x++ ) { echo '<option value="'.$x.'">'.$x.'</option>'; } ?> </select> <select name="player[1][minutes]" id="player[1][minutes]"> <option value="">Minutes</option> <option value=""></option> <?php for($y = 15; $y <= 59; $y+=15) { echo '<option value="'.$y.'">'.$y.'</option>'; } ?> </select> </li> I use some javascript to create new players as necessary so every player has a userid, hours, minutes played... After posting the query string looks like this /cLeagueHandler.php?player[1][userid]=1&player[1][hours]=3&player[1][minutes]=15&player[2][userid]=3&player[2][hours]=6&player[2][minutes]=45&submit=Save+Points player1 userid = 1 hours = 3 minutes = 15 player2....... The code i'm using to access the values is Code: [Select] print_r ($_GET); // test display form values foreach ($_GET as $key => $value) { echo '<br/>'.$key.'<br/> '; foreach ($value as $iKey => $iValue) { // Line 72 foreach ($iValue as $xKey => $xValue) { echo " The $xKey for Player $iValue is $xValue <br/>"; } } } The above code displays Array ( [player] => Array ( [1] => Array ( [userid] => 1 [hours] => 3 [minutes] => 15 ) [2] => Array ( [userid] => 3 [hours] => 6 [minutes] => 45 ) ) [submit] => Save Points ) player The userid for Player Array is 1 The hours for Player Array is 3 The minutes for Player Array is 15 The userid for Player Array is 3 The hours for Player Array is 6 The minutes for Player Array is 45 submit Warning: Invalid argument supplied for foreach() in .................cLeagueHandler.php on line 72 Line 72 is foreach ($value as $iKey => $iValue) { If anyone could help me with this it would be great appreciated.......I want to be able to build and sql string to Insert a players id, hours, minutes into a database......(obviously not incl the submit value!) Maybe this is not even the best way of approaching this.....I'm quiet new to PHP so apologies if this is long winded...I'm trying to give as much info as possible.... thanks in advance tmfl I've got an array like this: $firstquarter = array('January', 'February', 'March'); Then I'm adding it to a MySQL DB as follows: $insert = "INSERT INTO sometable (months) VALUES ('$firstquarter') "; $insertresult = mysql_query($insert) or die ('Error in Insert query: ' . mysql_error()); When I use PHPMyAdmin I see a this value stored in the DB: 'Array' Can I retrieve the values, by index, from this database field?? Hi all I have a question about how to store parsed data into a multidimensional arrays -- I can store items into an array, but multidimensional arrays mystify me a bit. Any help would be greatly appreciated. I'm storing the images in a table, grouped according to their table and their descriptions, so that later when I call the images, I can display them accordingly. I'm using the Simple HTML DOM Parser. So say I have two tables, one with three images, and another with one. I'd like the resulting to array to look like: Code: [Select] Array ( [0] => Array ( [0] => image1.jpg [1] => 1st Variation Description ) [1] => Array ( [0] => image2.jpg [1] => image3.jpg [2] => image4.jpg [3] => 2nd Variation Description ) ) This is what I have so far: Code: [Select] $html = str_get_html($vartables); $varinfo = array(); foreach($html->find('table') as $table){ $varinfo[] = $table->innertext; } print_r($varinfo); Which yields: Code: [Select] Array ( [0] => <tr> <td width=150> Description1 </td> <td><a href="image1.jpg"> <img src="image1" height=100 border=1></a> </td> </tr> [1] => <tr> <td width=150> Description2 </td> <td><a href="image2.jpg"> <img src="image2.jpg" height=200 border=1></a> </td> <td><a href="image3.jpg"> <img src="image3.jpg" height=200 border=1></a> </td> <td><a href="image4.jpg"> <img src="image4.jpg" height=200 border=1></a> </td> </tr> ) I'd like to strip out the html and keep the .jpg's and descriptions together in a multidimensional array...unfortunately my newbness is getting the better of me there, I'm researching but running into a roadblock. Thanks in advance for any help. i want to store some data that i have gained from a request at the planetfile of openstreetmap: so i have set up a database on my opensuse 13.1 i have created a db called test on the mysql-server on my opensuse: CREATE TABLE `pois` ( `id` bigint(20) unsigned NOT NULL, `lat` float(10,7) NOT NULL, `lon` float(10,7) NOT NULL, PRIMARY KEY (`id`) ) CREATE TABLE `pois_tag` ( `poisid` int(11) NOT NULL DEFAULT '0', `tagname` varchar(45) NOT NULL DEFAULT '', `tagvalue` varchar(255) DEFAULT NULL, PRIMARY KEY (`poisid`,`tagname`) ) Where each tagname/value pair is stored as a row in a separate table with the pois id Processing would be like this <?php $db = new mysqli(localhost,root,rimbaud,'test'); // use your credentials $xmlstr = <<<XML <data> <node id="2064639440" lat="49.4873181" lon="8.4710548"> <tag k="amenity" v="restaurant"/> <tag k="cuisine" v="turkish"/> <tag k="email" v="info@lynso.de"/> <tag k="name" v="Kilim - Café und Bar Restaurant"/> <tag k="opening_hours" v="Su-Th 17:00-1:00; Fr, Sa 17:00-3:00"/> <tag k="operator" v="Cengiz Kaya"/> <tag k="phone" v="06 21 - 43 755 371"/> <tag k="website" v="http://www.kilim-mannheim.de/"/> </node> <node id="2126473801" lat="49.4851170" lon="8.4756295"> <tag k="amenity" v="restaurant"/> <tag k="cuisine" v="italian"/> <tag k="email" v="mannheim1@vapiano.de"/> <tag k="fax" v="+49 621 1259 779"/> <tag k="name" v="Vapiano"/> <tag k="opening_hours" v="Su-Th 10:00-24:00; Fr-Sa 10:00-01:00"/> <tag k="operator" v="Vapiano"/> <tag k="phone" v="+49 621 1259 777"/> <tag k="website" v="http://www.vapiano.de/newsroom/?store=29"/> <tag k="wheelchair" v="yes"/> </node> <node id="667927886" lat="49.4909673" lon="8.4764904"> <tag k="addr:city" v="Mannheim"/> <tag k="addr:country" v="DE"/> <tag k="addr:housenumber" v="5"/> <tag k="addr:postcode" v="68161"/> <tag k="addr:street" v="Collinistraße"/> <tag k="amenity" v="restaurant"/> <tag k="name" v="Churrascaria Brasil Tropical"/> <tag k="phone" v="+496211225596"/> <tag k="wheelchair" v="limited"/> </node> <node id="689928440" lat="49.4798794" lon="8.4853418"> <tag k="amenity" v="restaurant"/> <tag k="cuisine" v="greek"/> <tag k="email" v="epirus70@hotmail.de"/> <tag k="fax" v="0621/4407 762"/> <tag k="name" v="Epirus"/> <tag k="opening_hours" v="Mo-Sa 12:00-15:00,18:00-24:00"/> <tag k="phone" v="0621/4407 761"/> <tag k="smoking" v="separated"/> <tag k="website" v="http://epirus-ma.blogspot.com/"/> <tag k="wheelchair" v="no"/> </node> <node id="689928445" lat="49.4799409" lon="8.4851357"> <tag k="amenity" v="restaurant"/> <tag k="cuisine" v="italian"/> <tag k="email" v="gianlucascurti@ristorante-augusta.de"/> <tag k="name" v="Ristorante Augusta"/> <tag k="opening_hours" v="Mo-Fr 12:00-14:00,18:00-23:00;Su 12:00-14:00,18:00-23:00"/> <tag k="phone" v="0621 449872"/> <tag k="website" v="ristorante-augusta.com/"/> <tag k="wheelchair" v="no"/> </node> </data> XML; $fields = array('id','name','lat','lon'); $xml = simplexml_load_string($xmlstr); // // PROCESS XML RECORDS // $poisdata = array(); $tagdata = array(); foreach ($xml->node as $node) { $nodedata = array_fill_keys($fields,''); $nodedata['id'] = intval($node['id']); $nodedata['lat'] = isset($node['lat']) ? floatval($node['lat']) : 0; $nodedata['lon'] = isset($node['lon']) ? floatval($node['lon']) : 0; $poisdata[] = vsprintf("(%d, %10.7f, %10.7f)", $nodedata); foreach ($node->tag as $tag) { $k = (string)$tag['k']; $v = (string)$tag['v']; $tagdata[] = sprintf("(%d, '%s', '%s')" , $nodedata['id'] , $db->real_escape_string($k) , $db->real_escape_string($v)); } } // // STORE THE DATA // $sql = "REPLACE INTO pois ('id','lat','lon') VALUES\n" . join(",\n", $poisdata); $db->query($sql); $sql = "REPLACE INTO pois_tag (poisid, tagname, tagvalue) VALUES\n" . join(",\n", $tagdata); $db->query($sql); // // DISPLAY THE DATA // $currentTags = array(); $sql = "SELECT DISTINCT tagname FROM pois_tag ORDER BY tagname = 'name' DESC, tagname"; $res = $db->query($sql); while (list($tn) = $res->fetch_row()) { $currentTags[] = $tn; } $thead = "<tr><th>id</th><th>lat</th><th>lon</th><th>" . join('</th><th>', $currentTags) . "</th></tr>\n"; $currid = $currlat = $currlon = 0; $sql = "SELECT p.id, lat, lon, tagname, tagvalue FROM pois p LEFT JOIN pois_tag t ON t.poisid = p.id ORDER BY p.id"; $res = $db->query($sql); $tdata = ''; while (list($id, $lat, $lon, $t, $v) = $res->fetch_row()) { if ($currid != $id) { if ($currid) { $tdata .= "<tr><td>$currid</td><td>$currlat</td><td>$currlon</td><td>" . join('</td><td>', $poisrow) . "</td></tr>\n"; } $currid = $id; $currlat = $lat; $currlon = $lon; $poisrow = array_fill_keys($currentTags,''); } $poisrow[$t] = $v; } $tdata .= "<tr><td>$currid</td><td>$currlat</td><td>$currlon</td><td>" . join('</td><td>', $poisrow) . "</td></tr>\n"; ?> <html> <head> <meta name="generator" content="PhpED 12.0 (Build 12010, 64bit)"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Tags</title> <meta name="author" content="Barand"> <meta name="creation-date" content="06/04/2014"> <style type="text/css"> body, td, th { font-family: arial, sans-serif; font-size: 10pt; } table { border-collapse: collapse; } th { background-color: #369; color: white; padding: 5px 2px; } td { background-color: #EEE; padding: 2px; } </style> </head> <body> <table border='1'> <?php echo $thead, $tdata; ?> </table> </body> </html> leeeds to the following errors.... PHP Fatal error: Call to a member function fetch_row() on a non-object in /home/martin/php/osm_200.php on line 121 martin@linux-70ce:~/php> php osm_200.php PHP Notice: Use of undefined constant localhost - assumed 'localhost' in /home/martin/php/osm_200.php on line 3 PHP Notice: Use of undefined constant root - assumed 'root' in /home/martin/php/osm_200.php on line 3 PHP Notice: Use of undefined constant rimbaud - assumed 'rimbaud' in /home/martin/php/osm_200.php on line 3 PHP Fatal error: Call to a member function fetch_row() on a non-object in /home/martin/php/osm_200.php on line 121 martin@linux-70ce:~/php> so what goes wrong here...? I have a Form that has 10 questions. When the User completes the Form, each Response needs to be a separate record. (My database has a many-to-many relationship with a "member" and "question" table joined by a "answer" table in the middle. And each Form field will go into its own unique record to make the many-to-many work.) At the top of my Form I have... if ($_SERVER['REQUEST_METHOD']=='POST'){ // Form was Submitted (Post). // Initialize Errors Array. $errors = array(); // Trim all form data. $trimmed = array_map('trim', $_POST); // ************************ // Validate Form Data. * // ************************ // Validate Answer1. if (strlen($trimmed['answer01']) >= 2 && strlen($trimmed['answer01']) <= 1024){ // Valid Answer1. $answerArray[0] = $trimmed['answer01']; }else{ // Invalid Answer1. $errors['question01'] = 'Answer must be 2-1024 characters.'; }//End of VALIDATE ANSWER1 // Validate Answer2. // : // : // Validate Answer10. And down farther in my code, I have each Field in my Form set up like this... Code: [Select] <!-- Question 1 --> <label for="question01">1.) Why did you decide to start your own business?</label> <textarea id="question1" name="answer01" cols="60" rows="8"><?php if (isset($answerArray[0])){echo htmlentities($answerArray[0], ENT_QUOTES);} ?></textarea> <?php if (!empty($errors['question01'])){ echo '<span class="error">' . $errors['question01'] . '</span>'; } ?> So if my Form works like I am thinking, all 10 Form Fields would end up here... Code: [Select] $answerArray[0] $answerArray[1] $answerArray[2] $answerArray[3] $answerArray[4] $answerArray[5] $answerArray[6] $answerArray[7] $answerArray[8] $answerArray[9] First of all, does that sound correct? If that part is correct, then how do I take the $answerArray[] and INSERT each value into a different record in my "answer" table?? Hope that makes sense?! Thanks, Debbie i have this script called view.php Code: [Select] <?php include 'db.inc'; $file = clean($file, 4); if (empty($file)) exit; if (!($connection = @ mysql_pconnect($hostName, $username, $password))) showerror(); if (!mysql_select_db("Php_test", $connection)) showerror(); $query = "SELECT mime, data FROM file WHERE id = $file"; if (!($result = @ mysql_query ($query,$connection))) showerror(); $data = @ mysql_fetch_array($result); if (!empty($data["data"])) { // Output the MIME header header("Content-Type: {$data["mime"]}"); // Output the image echo $data["data"]; } ?>after i have db.inc Code: [Select] <?php // These are the DBMS credentials $hostName = "localhost"; $username = "root"; $password = "oxioxi"; // Show an error and stop the script function showerror() { if (mysql_error()) die("Error " . mysql_errno() . " : " . mysql_error()); else die("Could not connect to the DBMS"); } // Secure the user data by escaping characters // and shortening the input string function clean($input, $maxlength) { $input = substr($input, 0, $maxlength); $input = EscapeShellCmd($input); return ($input); } ?>and i have my page witch part of it is this Code: [Select] <?php include 'db.inc'; $query = "SELECT id, name, mime FROM file"; if (!($connection = @ mysql_pconnect($hostName, $username, $password))) showerror(); if (!mysql_select_db("php_test", $connection)) showerror(); if (!($result = @ mysql_query ($query, $connection))) showerror(); ?> <h1>Image database</h1> <?php if ($row = @ mysql_fetch_array($result)) { ?> <table> <col span="1" align="right"> <tr> <th>Short description</th> <th>File type</th> <th>Image</th> </tr> <?php do { ?> <tr> <td><?php echo "{$row["name"]}";?></td> <td><?php echo "{$row["mime"]}";?></td> <td><?php echo "<img src=\"view.php?file={$row["id"]}\">";?></td> </tr> <?php } while ($row = @ mysql_fetch_array($result)); ?> </table> <?php } // if mysql_fetch_array() else echo "<h3>There are no images to display</h3>\n"; ?>i have do it right but for some reason it doesnt displays the pictures the type and the name are displayed normally but not the picture!! instead of them there are small icons of not existing pictures.. please i want help i really need to do it ok im back quicker than i thought.... i got my drop box sorted and i got it reloading the page. so it all works correctly. but how do i get the page to display information regarding the film i have selected in the drop box.? i have no code for this at the mo. also i would like the drop box to display the selected item at top of box when it refreshes code for drop box: Code: [Select] <FORM> <?php $result = mysql_query( "SELECT * FROM movie_info ORDER BY title ASC ") ; echo "<select name= Film onChange='submit()' >film name</option>"; while ($nt=mysql_fetch_array($result)){ ?> <?php echo "<option value='$nt[id]'>$nt[title] </option>"; } ?> </select> </FORM> any help would be great I'm making a game I have finished but have spent days and still can't figure out this part or how it should be done: Gamer will type in keyword on the form box on my page then click submit the page will connect to yahoo search then save/put the address bar URL search result of the keywords into a variable onto my page but the gamer will never have his page directed to yahoo but continue staying on my page while this all happens. Any Help in the right direction or some code would be appreciated? I have a basic table where I am trying to retrieve records that are filtered by a form request. Here is the code I have... $ps = $pdo->prepare("SELECT * FROM `Products` Where `Vendor` LIKE concat('%',?,'%'); $ps->execute(array($_POST['Vendor']));; echo "post=" . $_POST['vendor']; ////Displays correct data from form request $count = $ps->rowCount(); echo "Count=" . $count; ////Count = 0 although I know for a fact that there is 1 record that should be in there ////Used for display of records foreach ($ps as $row){ echo $row, PHP_EOL . "xxx<br>"; } Where is the incorrect code? I am new to php and pdo. Thank you in advance K There's many options available for downloading a URL - but I'm stuck. I've looked through all the ones I know, but none seem to pay attention to partial content. I'm trying to retrieve a URL that gives the following header: HTTP/1.1 206 Partial Content Content-Range: bytes 0-100000/631723 As you can see it dishes out the file in 100,000 byte chunks. Trouble is, when I use any method in PHP, ie file_get_contents, fopen, or even cURL, none of these continue on after retrieving the 100,000 bytes. End result, I have a 100,000 byte file. What I need is to get the PHP script to grab all the data, in the example above, all 631,723 bytes. How can I do this? i am trying to retrieve messages with some code. It seems to be a bit more complicated that i thought it would be. so here it goes: Code: [Select] $query = "SELECT * FROM memberMail WHERE userIDFrom='92' AND unread='1'"; $result = mysql_query($query) or die(mysql_error()); if (mysql_num_rows($result) > 0) { $row = mysql_fetch_array($result) or die(mysql_error()); $num_rows = mysql_num_rows($result); echo "You have (" . $num_rows . ") unread message(s)."; $i = 0; for($i; $i<$num_rows; ++$i) { if($row[$i[unread]] == "1") { echo $row[$i[message]] . "<p>"; } } } what i am trying to do, is print out the messages from the records that are unread, and are from a certain user. i don't think this for statement will pick up the record numbers that got matches though. and i am not entirely sure about the $row statements in the for statement either. |