corillo181 Posted May 20, 2006 Share Posted May 20, 2006 [code]<?php $rows=9; $col=1; $users=mysql_query("SELECT username FROM users"); while($user=mysql_fetch_array($users)){ for($r=1;$r <=$rows; $r++){ echo "<tr>"; } for($c=1;$c <=$col; $c++){ echo "<td>".$user['username']."</td>"; } } echo "</tr>"; ?> [/code]how i fix so that the rows goes with it.. becuase if i put the { below the colums loop it just lopps the name 9 times each.. Quote Link to comment https://forums.phpfreaks.com/topic/10045-minor-loopin-problem/ Share on other sites More sharing options...
.josh Posted May 20, 2006 Share Posted May 20, 2006 well, seeing as how you didn't bother to be real specific, i'm going to assume that you want to make a table with 1 username per row:[code]<?php $users=mysql_query("SELECT username FROM users"); echo "<table>"; while($user=mysql_fetch_array($users)){ echo "<tr><td>". $user['username']."</td></tr>"; } echo "</table>"; ?> [/code] Quote Link to comment https://forums.phpfreaks.com/topic/10045-minor-loopin-problem/#findComment-37347 Share on other sites More sharing options...
corillo181 Posted May 20, 2006 Author Share Posted May 20, 2006 this is what i was looking for with this i can control my table by just changing the num or the % number.. my problem still that i can't work a query into it.. becuase the <td> sends the same name over and over..how i do that?[code=php:0] echo '<tr>';$num=10; for($x=1; $x<=$num; $x++) { echo '<td>name</td>'; if($x % 5 == 0) { echo '</tr> <tr>'; } } echo '</tr>';[/code].. Quote Link to comment https://forums.phpfreaks.com/topic/10045-minor-loopin-problem/#findComment-37350 Share on other sites More sharing options...
corillo181 Posted May 20, 2006 Author Share Posted May 20, 2006 this is what i was looking for with this i can control my table by just changing the num or the % number.. my problem still that i can't work a query into it.. becuase the <td> sends the same name over and over..how i do that?[code=php:0] echo '<tr>';$num=10; for($x=1; $x<=$num; $x++) { echo '<td>name</td>'; if($x % 5 == 0) { echo '</tr> <tr>'; } } echo '</tr>';[/code] Quote Link to comment https://forums.phpfreaks.com/topic/10045-minor-loopin-problem/#findComment-37388 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.