Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP Only Showing 1 ID

Status
Not open for further replies.

t5amec

Programmer
Aug 14, 2003
112
GB
I have been dabling with link PHP and MySQL and I have worked the basics.

One problem, if you check it out here:

You will get a form, posting to a database, enter details and click submit, you will get a message saying Cheers! and a link to view, all entries, but it only shows the first entrY i submitted, although in the database there is at least three...

the code for the view.php (viewing page) is as follows:
Code:
<html>
<head>
<title>view.php</title>

<?php
$db = mysql_connect('localhost','*******','******');
mysql_select_db('themalloys_uk_db',$db);

$requete = "SELECT * FROM test";
$result = mysql_query ($requete,$db);
$test = mysql_fetch_object($result);
mysql_free_result($result);
?>

</head>
</body>
<?php echo $test->name ?>
<br>
<?php echo $test->email ?>
<br>
<?php echo $test->hobby ?>
<br>
<?php echo $test->comments ?>
</body>
</html>
Can you see where I have gone wrong?

Make Sense? I hope so (-:
 
you need to loop through the result set to display all data sets:

$requete = "SELECT * FROM test";
$result = mysql_query ($requete,$db);
while($test = mysql_fetch_object($result)) {
echo $text->name.'<br>';
echo $text->email.'<br>';
echo $text->hobby.'<br>';
echo $text->comments.'<br>';
}
mysql_free_result($result);

 
nice one dude, cheers for your help...

Make Sense? I hope so (-:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top