problem with developing table

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
timbo777
Forum Newbie
Posts: 1
Joined: Wed May 18, 2005 7:46 am

problem with developing table

Post 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
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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;
}
Post Reply