hazz995 Posted January 29, 2010 Share Posted January 29, 2010 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 More sharing options...
Shocker88 Posted January 29, 2010 Share Posted January 29, 2010 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 More sharing options...
hazz995 Posted January 29, 2010 Author Share Posted January 29, 2010 I changed the mysql_connect values before posting it in here. But thanks, I managed to get it working with the code you tidied up, just had to correct a few small things but I'm getting results Link to comment https://forums.phpfreaks.com/topic/190248-member-list-loop/#findComment-1003757 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.