将一列数据划分为四列


Dividing the One Column Data into Four Columns

我在mysql表中有35条statename记录。我把数据分成两列这是我的要求的php代码

<td>
<table class="statetable">
<?
//******Fetching State Name Dynamically*****//
$fetchstate = mysql_query("SELECT LocationName FROM servicedesklocationmaster group by      LocationName ASC");
$half1   = floor(mysql_num_rows($fetchstate)/2);
echo $half1;
$count  = 0;
// First Half State
while($count <= $half1 && $row = mysql_fetch_array($fetchstate))
{
$statename = $row['LocationName'];
$count++;
?>
<tr>
<td>                    
<font size="1.5">
<input type="checkbox" name="Location[]" id="Location"  checked value="<?php echo     $statename;?>" onClick="CheckEachAsset()"><?php echo $statename;?><br>
</font>
</td>
<?
}
//echo $count;
?>
</tr>
</table>
</td>
<td>
<table class="statetable">
<?
// Second Half State
while($row = mysql_fetch_array($fetchstate))
{
$statename = $row['LocationName'];
?>
<tr>
<td>
<font size="1.5">
<input type="checkbox" name="Location[]" id="Location"  
checked value="<?php  echo  $statename;?>" onClick="CheckEachAsset()"><?php echo            $statename;?><br>
</font>
</td>
<?
}
?>
</tr>
</table>
</td>

现在,根据我的新要求,我想把它分为4列,有人能建议我吗如何实现

$quater = floor(mysql_num_rows($fetchstate)/4);
$count = 0;
while($row = mysql_fetch_array($fetchstate)) {
    if($count < $quater) {
     // echo table content1
    }
    if($count >= $quater &&  $count < $quater*2) {
      // echo table content2
    }
    if($count >= $quater*2 &&  $count < $quater*3) {
      // echo table content3
    }
    if($count >= $quater*3 &&  $count < $quater*4) {
     // echo table content4
    }
    $count++;
}
 <td>
    <table class="statetable">
    <?
    $fetchstate = mysql_query("SELECT LocationName FROM servicedesklocationmaster group by          LocationName ASC");
    $quart= floor(mysql_num_rows($fetchstate)/4);
    echo $quart;
    $count  = 0;
    $times=0;
    while($times<=4 && $row = mysql_fetch_array($fetchstate))
    {
    $statename = $row['LocationName'];
    $count++;
    $times++;
    ?>
    <tr>
    <td>                    
    <font size="1.5">
    <input type="checkbox" name="Location[]" id="Location"  checked value="<?php echo     $statename;?>" onClick="CheckEachAsset()"><?php echo $statename;?><br>
    </font>
    </td>
    <?
    if($count==$quart && $times!=4){
    $count=0;
    ?>
    </tr>
    </table>
    </td>
    <td>
    <table class="statetable">
<?
}
    }
    //echo $count;
    ?>
    </tr>
    </table>
    </td>