Well, I’ve been screwing around with this for about 6 hours and I just can’t get it to work right. I’m sure it’s just something stupid i’m doing, maybe your guys’ fresh eyes can point it out.
$i = 0;
$sql = mysql_query("SELECT type, info, url FROM alerts WHERE username = '$user_logged_in' ORDER BY id ASC LIMIT 40");
$div_grid = '<div style="float:left;">';
while ($row = mysql_fetch_array($sql))
{
if ($i < 11){
$display = '<a href="' . $row['info'] . '"><div class="' . $row['type'] . "_alert" . '" style="float:left; margin-left:-22px;"></div></a>';
$div_grid .='<div style="float:left;">' . $display . '</div>';
$i++;
}
if ($i > 11){
$display = '<a href="' . $row['info'] . '"><div class="' . $row['type'] . "_alert" . '" style="float:left; margin-left:-22px; margin-top:14px;"></div></a>';
$div_grid .='<div style="float:left;">' . $display . '</div>';
$i++;
}
}
$div_grid .= '</div>';
echo $div_grid;
For some reason, I get the whole first line of these div outputs, but the second line isn’t coming out. Except if I set the $i >= 11{ which then gives me TWO id 11s. Obviously i’m missing something crucial here. Any ideas?
Also, in the end, i’d like to make the if statements to be >= 10 && <= 20; which hasn’t seemed to be working so far but I’m guessing there’s an issue somewhere else first.
You are incrementing
$i++twice. It is also necessary to use>=since you will otherwise be missing row 11, and the loop will run with no output ($1==11, so it’s not less than or greater than 11) until the end of your recordset.