Page 1 of 1
for loop table
Posted: Fri Sep 07, 2012 4:51 am
by jayson.ph
Hi all,
i have a table for loop with 20rows and 14columns and i have only 1 record here my db mysql. and now how to display a 1 record into 20rows that i set into loop. the 20rows that i set into loop it should be only 1record should be displayed, the rest 19 rows are empty?
Re: for loop table
Posted: Fri Sep 07, 2012 7:03 am
by social_experiment
The value that determines the amount of times the for loop is executed should be the amount of rows in your database.
Code: Select all
<?php
$rows = mysql_num_rows($sql);
for($i=0; $i<=$rows; $i++) { // loop will now execute until $i is equal to $rows
// show data
}
?>
Hope this helps

Re: for loop table
Posted: Sat Sep 08, 2012 10:59 am
by jayson.ph
thank for quick reply,
<?php
$rows = mysql_num_rows($sql);
for($i=0; $i<=$rows; $i++) { // loop will now execute until $i is equal to $rows
// show data
}
?>
and yes it work but no empty rows are happen?
Re: for loop table
Posted: Sat Sep 08, 2012 11:30 am
by social_experiment
Do you want to spread the single row over 20 rows?
Re: for loop table
Posted: Sat Sep 08, 2012 11:53 am
by Celauran
You want 20 rows no matter what?
Code: Select all
$i = 0;
foreach ($result as $row)
{
// display results
$i++;
}
for ($i; $i < 20; $i++)
{
// empty row
}