help llooping a table
Posted: Fri May 19, 2006 7:19 pm
with variables from mysql
Code: Select all
what i want is the table and usernames to be display in any kind
of rows and colums i specify
*/
// here i'm looking for the user id and name
$users=mysql_query("SELECT ID,username FROM users");
while($user=mysql_fetch_array($users)){
// the variables
$id=$user['ID'];
$username=$user['username'];
$rows=9;//i want this number to control the number of rows in the table
$col=4;// i want this to be the number of coloums on my table
//i want to be able to custumize how many rows and colum i can put in a table
//this is the kind of loop i want
for($r=1;$r <=$rows; $r++){//loop for the ros
echo "<tr>";
for($c=1;$c <=$col; $c++){// and looping for the colums with the username inside the<td>
echo "<td>$username</td><td></td>";
}
echo "</tr>";
}
}
/*so if i run the script like i want it would display something like
+----+--------+
| ID |username| <--- any number of rows i want
+---+---------+
^ ^ and number of cells"colums" i want
*/