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 Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trouble showing users in a list

Status
Not open for further replies.

internetguy

Technical User
Nov 22, 2003
57
US
I am having trouble showing a list of users in a database on a page. I have a page where it asks which users to delete, and I want a list to the side to see all the names, but when I try the page it says that it "cannot jump" to the last row in my table, here is my code...

<?php
echo &quot;<h1>Users</h1>&quot;;
$db = mysql_connect('localhost','root');
mysql_select_db('users');
$query = &quot;SELECT * FROM info LIMIT 30&quot;;
$result = mysql_query($query);
$num = mysql_num_rows($result);
for ($i = 0; $i < $num; $i++)
{

}
$row = mysql_result($result,$i,'title');
echo &quot;<br>&quot;.$row['url'];
?>

please help, thank you
 
There are a number of problems with your code.

Your code appears to attempt to display only the last name in the list. This does not sound like what you want.

I'm also not sure what the for loop in your code is supposed to do.

Also, the PHP manual recommends using the higher-performance mysql_fetch_* group of functions over mysql_result.

You also have no error-checking.

You are also using the user root, and that user apparently does not require a password to login. I strongly recommend that you create a separate user, and require that user to supply a password.

If you want to display all the names, something like:

Code:
<?php
echo &quot;<h1>Users</h1>&quot;;
$db = mysql_connect('localhost','root') or die('Could not connect');
mysql_select_db('users', $db);
$query = &quot;SELECT * FROM info LIMIT 30&quot;;
$result = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_assoc($result))
{
   echo &quot;<br>&quot;.$row['url'];
}
?>

will probably do it.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
Thank you, I did not include the error checking because I had already done the error checking and felt it was redundant. I left it in this time for safety and added the assoc in $row and it works great. Thanks for the help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top