Wildhalf Posted February 27, 2008 Share Posted February 27, 2008 I am using the following code to return all entries into my database with the letters begining with $letter which is taken from my URL $sql_1 = mysql_query("SELECT * FROM tbl_offers WHERE business_name LIKE '$letter%'"); $data_1 = mysql_fetch_array($sql_1 ); It works but what i want todo is print all returned values for offer, example below prints one but i want to print all entries. $offer = $data_1["offer"]; print "</BR>offer : $offer"; Anyone got any ideas??? Thanks in advance. Kieron Quote Link to comment Share on other sites More sharing options...
revraz Posted February 27, 2008 Share Posted February 27, 2008 Use a while loop Quote Link to comment Share on other sites More sharing options...
Neptunus Maris Posted February 27, 2008 Share Posted February 27, 2008 That all seems to be rightly coded...just may be the value from the URL is it: $letter = $_GET['letter']; Quote Link to comment Share on other sites More sharing options...
Neptunus Maris Posted February 27, 2008 Share Posted February 27, 2008 Use a while loop Oh yes...i kinda got confused...yes the while loop add this to your code //DELETE THIS LINE $data_1 = mysql_fetch_array($sql_1 ); //----------------------------------- Add this ------- while ($data_1 = mysql_fetch_array($sql_1)) { print "$data_1[offer]<br>"; } -------------- Quote Link to comment Share on other sites More sharing options...
Wildhalf Posted February 27, 2008 Author Share Posted February 27, 2008 I believe im getting the letter fine using the following code. // Create variables from URL. $letter = $_REQUEST['letter']; print "letter : $letter"; It prints the right letter anyways. I'm returning and printing the first result of the field offer to screen. but want it to print all results. How would i use a while loop with arrays?? Quote Link to comment Share on other sites More sharing options...
Wildhalf Posted February 27, 2008 Author Share Posted February 27, 2008 Neptunus Maris thanks a bunch that worked great Quote Link to comment Share on other sites More sharing options...
Barand Posted February 27, 2008 Share Posted February 27, 2008 Here's a general-purpose function to output query results <?php include 'db.php'; //connnection stuff function table2table($query) { $result = mysql_query($query) or die (mysql_error()); $str = "<TABLE border='1' cellpadding='4'>\n"; // column headings $str .= "<tr>\n"; while ($fld = mysql_fetch_field ($result)) { $str .= "<th>{$fld->name}</th>\n"; } $str .= "</tr>\n"; // list data while ($row = mysql_fetch_row($result)) { $str .= "<tr>\n"; foreach ($row as $field) { $str .= "<td>$field</td>\n"; } $str .= "</tr>\n"; } $str .= "</TABLE>\n"; return $str; } // // call function // echo table2table('select * from tablename'); ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.