member list

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
cheatboy00
Forum Contributor
Posts: 151
Joined: Sat Jun 29, 2002 10:36 am
Location: canada
Contact:

member list

Post by cheatboy00 »

o.k. i'm obivously creating a member list.... and it SHOULD be easy but its not working i'm incompetent ..... help!!

i have this:

Code: Select all

$qry = mysql_query ("SELECT * FROM users ORDER BY id LIMIT 1,20");
$row = array(mysql_fetch_assoc($qry));

for ($i = 0; $i < $rows; $i++)&#123;
   echo "<TR><TD ALIGN=CENTER VALIGN=TOP WIDTH="5%">";
      echo $row&#1111;$i]&#1111;'id'];
   echo "</TD>";

   echo "<TD ALIGN=LEFT VALIGN=TOP>";
      echo $row&#1111;$i]&#1111;'login'];
   echo "</TD>";

   echo "<TD ALIGN=CENTER VALIGN=TOP>";
      echo $row&#1111;$i]&#1111;'date'];
   echo "</TD></TR>";
      
&#125;
as you can see i want to order all the users in users table by their id... so i want 2 arrays....
one for each row... then inside that i want an associative array..

i want to output the first 20 people...

but nothing shows up
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

with mysql_fetch_assoc you fetch a single result row as an associative array, so you can access the fields by their db-field-name.
However, the important thing is: you only fetch a single line. So you have to do it as long as there are result-rows remaining. You may do this by a for-loop with mysql_num_rows or even simpler with a while-loop having the result of mysql_fetch_assoc as condition

Code: Select all

$qry = mysql_query ('SELECT * FROM users ORDER BY id LIMIT 1,20') or die('query failed: '.mysql_error());
while($row = mysql_fetch_assoc($qry))
&#123; 
   echo '<TR><TD ALIGN="CENTER" VALIGN="TOP" WIDTH="5%">'; 
      echo $row&#1111;'id']; 
   echo "</TD>"; 

   echo '<TD ALIGN="LEFT" VALIGN="TOP">'; 
      echo $row&#1111;'login']; 
   echo "</TD>"; 

   echo "<TD ALIGN="CENTER" VALIGN="TOP">"; 
      echo $row&#1111;'date']; 
   echo "</TD></TR>"; 
&#125;
User avatar
cheatboy00
Forum Contributor
Posts: 151
Joined: Sat Jun 29, 2002 10:36 am
Location: canada
Contact:

Post by cheatboy00 »

thanks
Post Reply