Jump to content

Member list loop


hazz995

Recommended Posts

I'm having trouble creating a loop that will echo all members in the database.

I'm trying to get every member in the database to come out like this:

 

Name1 | Date Registered

Name2 | Date Registered

and so on...

 

<?php
$user="root";
echo "Currently ";
$connect=mysql_connect("localhost","dbuser","dbpass") or die("Could not connect");
mysql_select_db("dbmembers") or die("Could not find database");

$query = "SELECT * FROM users ORDER BY name DESC LIMIT 20";
$res = mysql_query($query) or die("Couldn't execute query: ".mysql_error());
$numrows = mysql_num_rows($query);

echo "$numrows registered users."

 while ($user = mysql_fetch_assoc($res))
{
  echo "
	  ".$user["username"]." 
	   ".$user["date"]."<br> 
	   
	   ";
}
?>

Link to comment
Share on other sites

You'll have to provide a bit more info - what kind of problem are you running into? (I'm assuming the mysql_connect values you have are actually variables that you've replaced? Or is that a direct copy from what you have on your server?) I've slightly changed some of the code since the snippet you posted was a little dirty - try this though it probably won't fix an issue just clean up the code :)

 

   <?php
   $user="root";
   echo "Currently ";
   $connect=mysql_connect("localhost","dbuser","dbpass") or die("Could not connect");
   mysql_select_db("dbmembers") or die("Could not find database");
   
   $query = "SELECT * FROM users ORDER BY name DESC LIMIT 20";
   $res = mysql_query($query) or die("Couldn't execute query: ".mysql_error());
   $numrows = mysql_num_rows($query);
   
   echo $numrows . "registered users.";

    while ($user = mysql_fetch_assoc($res))
{
    echo $user['username'];
    echo $user['date'] . "<br />";
}
   ?>

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.