Jump to content

displaying only one record:


rofl90

Recommended Posts

Heres my code

 

<?php
$host = 'xx';
$user = 'xx';
$pass = 'xx';
$db = 'xx';
mysql_connect($host, $user, $pass) or die(mysql_error());
mysql_select_db($db);

$info = mysql_query("SELECT * FROM support;");
$i = mysql_fetch_object($info);

echo "<table border='1'>";
echo "<tr> <th>Name</th> <th>Email</th> <th>Reason</th> <th>Message</th> </tr>";
// keeps getting the next row until there are no more to get
// Print out the contents of each row into a table
echo "<tr><td>"; 
echo $i->name;
echo "</td><td>"; 
echo $i->email;
echo "</td><td>"; 
echo $i->reason;
echo "</td><td>"; 
echo $i->message;
echo "</td></tr>"; 
} 

echo "</table>";
mysql_close()
?>

Link to comment
https://forums.phpfreaks.com/topic/92037-displaying-only-one-record/
Share on other sites

the issue is that you must loop through the results:

 

while ($i = mysql_fetch_object($info))
{
  // row echoing stuff here
}

 

the resource returns a resultset that requires a loop to go through.  when you only use one call of mysql_fetch_object(), it'll just grab the row the resultset is pointing to.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.