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?
for loop table
Moderator: General Moderators
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: for loop table
The value that determines the amount of times the for loop is executed should be the amount of rows in your database.
Hope this helps 
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
}
?>“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Re: for loop table
thank for quick reply,
and yes it work but no empty rows are happen?<?php
$rows = mysql_num_rows($sql);
for($i=0; $i<=$rows; $i++) { // loop will now execute until $i is equal to $rows
// show data
}
?>
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: for loop table
Do you want to spread the single row over 20 rows?
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Re: for loop table
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
}