database records not displaying |
database records not displaying |
minidiapolis |
Oct 5 2011, 11:04 AM
Post
#1
|
Serious Coder Group: Members Posts: 437 Joined: 3-September 06 Member No.: 57 |
Hi, can someone help me understand why it 's only printing the first record in the database ?
<?php require_once("functions.php"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <?php DatabaseConnection(); mysql_select_db("auntievics"); $query= "SELECT product_id FROM treats"; $result_set= mysql_query($query); if ($result_set){ $products= mysql_fetch_row($result_set); foreach ($products as $value){ print $value; } print "<br />"; } //print_r(mysql_fetch_row($result_set)); ?> </body> </html> |
Brian Chandler |
Oct 5 2011, 11:29 PM
Post
#2
|
Jocular coder Group: Members Posts: 2,460 Joined: 31-August 06 Member No.: 43 |
It helps to put program inside *code* tags.
CODE if ($result_set){ $products= mysql_fetch_row($result_set); foreach ($products as $value){ print $value; } print "<br />"; } Well, you get one row from the database with mysql_fetch_row, then print all the values in it with no spaces. So if a typical entry is code-title-price-stock, I'd expect to see something like E11067Tibetan mandala30001 Why would you expect anything else? Notice how your variable names are "wrong": you've use 'products' to hold one entry... etc. |
Lo-Fi Version | Time is now: 24th April 2024 - 04:25 AM |