Michael Grigsby
Michael Grigsby

Reputation: 12163

excluding a row from a mysql database outputting

Every third element extracted from the database will output in the large box, while every other element will output in the small box. What I need it to do is exclude the third element when the small box is outputted. Any ideas on how to accomplish this?

while($array = mysql_fetch_assoc($result)) {
if($i % 3 == 0) {
// large box
echo '<div class="box" style="width: 692px; height: 218px">' . $array['feedName'] . '</div>';
}
// small box
echo '<div class="box" style="width: 246px; height: 218px">' . $array['feedName'] . "<br></div>";
// exclude the third element
$i++;
}
}

Upvotes: 0

Views: 73

Answers (2)

勿绮语
勿绮语

Reputation: 9320

divide by 6 and get the remainder (%)
if (remainder == 0 or 3) {
    large box
} else if (remainder == 1 or 5) {
    small box
} 

Upvotes: 1

Bryan
Bryan

Reputation: 2211

If I understand what you want correctly (each third item is in the large box and kept out of the small box), you just use an else clause in your if.

while($array = mysql_fetch_assoc($result)) {

    if($i % 3 == 0) {
        // large box
        echo '<div class="box" style="width: 692px; height: 218px">' . $array['feedName'] . '</div>';
    }
    else {
        // small box
        echo '<div class="box" style="width: 246px; height: 218px">' . $array['feedName'] . "<br></div>";
    }

    $i++;
}

Upvotes: 3

Related Questions