Jump to content

minor loopin problem


corillo181

Recommended Posts

[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..
Link to comment
Share on other sites

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]

Link to comment
Share on other sites

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]..
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.