用while更改div的值

I need put this divs in this order:

<div class="col-md-9"> 1 box </div>
<div class="col-md-3"> 2 box </div>
<div class="col-md-3"> 3 box </div>
<div class="col-md-9"> 4 box </div>
<div class="col-md-9"> 5 box </div>
<div class="col-md-3"> 6 box </div>
<div class="col-md-3"> 7 box </div>
<div class="col-md-9"> 8 box </div>

An continue in this order. I try make it with a while but I can't find an algoritm that put me the divs in this order.

This is the code that I try but don't work:

$count = 0;

    while($items = mysql_fetch_array($consult))
    {
        if($count % 2 == 0)
        {
            echo '<div class"col-md-9"> '.$items['title'].' </div>';
        }
        else
        {
            echo '<div class="col-md-3"> '.$items['title'].' </div>';
        }
    }

This show me:

<div class="col-md-9"> value </div>
<div class="col-md-3"> value </div>
<div class="col-md-9"> value </div>
<div class="col-md-3"> value </div>

Any idea?

Regards

1st: don't use MYSQL_* commands, they are deprecated and unsafe!

2nd: This should do. Notice: I did not test it, just wrote a quick example:

$count = 1;
$md = 9;

while ($items = mysql_fetch_array($consult)) {
    $count++;
    echo '<div class="col-md-' . $md . '"> ' . $items['title'] . ' </div>';

    if ($count > 1) {
        $md = $md == 3 ? 9 : 3;
        $count = 0;
    }
}

You have two options:

  1. Make sure you receive the values in order by adding "ORDER BY" to your sql statement.
  2. First retrieve all values from the SQL in an arrray, then sort the array (e.g. asort) and then run your loop to produce the DIVs

If you can I would recommend option 1. Its usually faster to use your the DB for sorting.