Forum Moderators: coopster
I understand the process needed but it seems that I'm putting it in the wrong place as it does not work and the for line generates a unexpected ")", expecting ";" line.
Here's what I would like to add
$MyNumber = 1;for ($MyNumber <= 10)
{"$MyNumber" (it would be listed as the table id so I didn't echo or print it)
$MyNumber++;
}
Here's my existing code
$row_count = 0;
while($r=mysql_fetch_array($result))
{$name=$r["name"];
$image=$r["image"];
$url=$r["url"];
$description=$r["description"];
$id=$r["id"];
echo "<TD><div align=\"center\">
<center><TABLE id=\"$MyNumber\" WIDTH=200 BORDER=0 CELLPADDING=0 CELLSPACING=0 style=\"border-collapse: collapse\" bordercolor=\"#111111\">
snip - rest of the code";
$count++;
if ($count==3) {
echo "</tr><tr>";
$count=0;
}
$row_count++;
}
echo "</tr></table>";
You also say you want to create a new table with the row number inserted as an id, but this table is inside of the loop, so haw many results do you actually want before it is closed and a new one is started?
So, I guess to help I would need to know, when should a new table actually start? Should it be after every 3rd time through, like your <tr>? Or, is it based on some other factor?
The way it is now, you would need multiple loops, individually, not nested, because you are using all of your results from the DB in this loop, while($r=mysql_fetch_array($result)) , so even if you had the nesting correct, you would have to have another connection string to get anything, except blank tables/rows to display.
Maybe I am missing something?
Justin
Each table is closed before the $count part comes into play.
What I would like is to have the code +1 every table every time this code is looped to the bolded part
<center><TABLE id=\"$MyNumber\" WIDTH=200 BORDER=0 CELLPADDING=0 CELLSPACING=0 style=\"border-collapse: collapse\" bordercolor=\"#111111\">
{
echo "</table>";
$MyNumber++;
}
as long as this line is only read when a table is actually closed, the count would only increase when a table is closed. Then if you want to stop the while loop, at 10 tables, regardless of the DB results you could add an 'if... break'
EG
{
$MyNumber++;
if($MyNumber == 11)
break;
echo "</table>";
}
Since the ++ is at the end of the loop, the break has to be one higher than the # of tables you want, because you will not complete the last one.
It looks like you have a </table> out of the loop to close the last table, so you would want to 'break', before the close or you will have double close tags in your html.
* You should be able to put the table first if this is not the case, then you will close the table before you 'break'.
This should work if I am understanding what you are asking correctly.
Hope so.
Justin
Added: You can actually add the 'if...break' anywhere it best suits your purposes, maybe right at the end of the full loop would be better?