dual_alliance Posted September 22, 2006 Share Posted September 22, 2006 Hello, l have the following code:[code=php:0] <?php // Read information from MySQL database $query = "SELECT `userid`, `username`, `m.group` FROM `users` ORDER by `userid` ASC "; $result = mysql_query($query) or die("Problem with the query: $query<br>" . mysql_error()); $rows = mysql_fetch_assoc($result); $mgroup = $rows['m.group']; $group = array( 1=>"Banned", 2=>"Member", 3=>"Donator", 4=>"Game Moderator", 5=>"Forum Moderator", 6=>"Global Moderator", 7=>"Graphic's Admin", 8=>"General Admin", 9=>"Root Admin" ); while ($row = mysql_fetch_array($result)){ ?> <tr> <td><p class="description"> <?php echo $row['userid']; ?></p></td> <td><p class="description"> <?php echo $row['username']; ?></p></td> <td><p class="description"> <?php echo $group[$mgroup]; ?></p></td> <td><p class="description">View Profile</p></td> </tr> <?php } ?>[/code]When l view this it prints out that their all Root Admin ???If you could shed some light on this l would appreciate it.Thanks Quote Link to comment Share on other sites More sharing options...
ronverdonk Posted September 22, 2006 Share Posted September 22, 2006 $mgroup is set only at the first row and is not changed after that. Move it to the while loop.Ronald 8) Quote Link to comment Share on other sites More sharing options...
dual_alliance Posted September 22, 2006 Author Share Posted September 22, 2006 Thanks for finding the problem :), but how would l do that? Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted September 22, 2006 Share Posted September 22, 2006 You have the loop constructed incorrectly, such that the variable $mgroup is only set once to the value of the first record. If that record was an "Root Admin", you would show that for all of the records.Change you code to something like:[code] <?php$group = array(1=>"Banned", 2=>"Member", 3=>"Donator", 4=>"Game Moderator", 5=>"Forum Moderator", 6=>"Global Moderator", 7=>"Graphic's Admin", 8=>"General Admin", 9=>"Root Admin" ); // Read information from MySQL database $query = "SELECT `userid`, `username`, `m.group` FROM `users` ORDER by `userid` ASC "; $result = mysql_query($query) or die("Problem with the query: $query<br>" . mysql_error()); while($rows = mysql_fetch_assoc($result)) { $mgroup = $rows['m.group'];?> <tr> <td><p class="description"> <?php echo $row['userid']; ?></p></td> <td><p class="description"> <?php echo $row['username']; ?></p></td> <td><p class="description"> <?php echo $group[$mgroup]; ?></p></td> <td><p class="description">View Profile</p></td> </tr><?php } ?>[/code]Ken Quote Link to comment Share on other sites More sharing options...
dual_alliance Posted September 22, 2006 Author Share Posted September 22, 2006 Thankyou both for you help, kenrbnsn that worked prefectly thanks once again. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.