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
https://forums.phpfreaks.com/topic/190248-member-list-loop/
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
https://forums.phpfreaks.com/topic/190248-member-list-loop/#findComment-1003751
Share on other sites

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.