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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.