Welcome Guest, Not a member yet? Register   Sign In
How to display the query results in a random html table?
#5

[eluser]jedd[/eluser]
Note that both richfearless's and BrianDHall's approaches require a ++ in there somewhere - a $count++ and a $i++ respectively.

Code:
// As an example, pilfering Brian's demonstration code

$i = 0;

echo '<tr>';
foreach ($results as $r)  {
    if ($i > 3)  {
        echo '</tr><tr>';
        $i = 0;
        }

    echo "<td>$r</td>";

    $i++;
    }

echo '</tr>';

Note also - using a modulus approach means you wouldn't have to reset the $i=0 within your test on each iteration, which would reduce your code count by one line, but would be arguably be less obvious for those not familiar with that pattern .. take your pick.


EDIT: Oh, btw, what does 'random' mean in your context? I feel we may possibly have missed your intent here.


Messages In This Thread
How to display the query results in a random html table? - by El Forum - 10-14-2009, 04:10 PM



Theme © iAndrew 2016 - Forum software by © MyBB