The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> database records not displaying
minidiapolis
post 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>
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Brian Chandler
post Oct 5 2011, 11:29 PM
Post #2


Jocular coder
********

Group: Members
Posts: 2,298
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.

User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 28th January 2020 - 05:36 AM