Page 1 of 1

problem with developing table

Posted: Mon Jun 06, 2005 8:49 am
by timbo777
I'm not sure how best to describe this problem and what kinda problem it really is. I've been learning php for a year or two now and i've not come across anything like this. It seems like the solution should be simple but for the life of me I can't work out what it should be.

Basically I'm pulling out a set of results from a database and then producing them in a table. Which is fine. Now the person I'm doing this for wants me to continue with empty rows to the bottom of the page.

This would mean producing ten rows for the page, so depending on how many results I recieve from the database determines the amount of blank rows - could be 9 or could be 0.

Would some form of loop work here? This was my initial feeling, but I'm not so sure as the table row you'd be looping isn't a numerical value.

So basically I work out how many results ($result) are produced from the database and I take it away from ten to leave me $i. So

10- $result= $i

$row would then equal something like:

echo "<tr>$a</tr>
<tr>$b</tr>
<tr>$c</tr>
<tr>$d</tr>"

(or is it td - i sometimes get them mixed up!)

So I'd be looking at:

$row x $i

Which seems simple, except discounting that $row is not a numerical value.

Hope someone can help.

Thanks

t

Posted: Mon Jun 06, 2005 9:06 am
by timvw

Code: Select all

$todo = 10;
$done = 0;

...
$rs = mysql_query($query);
...

while ($row = mysql_fetch_assoc($rs))
{
  // do stuff with $row
  // we've done a row
  ++$done;
}

while ($done < $todo)
{
  // print empty
  // we've done a row
  ++$done;
}