如何根据某些偏好获取MySQL中的备用行?

I have the following table -

S.No. (Auto Increment, Primary Key)
Timestamp (Records date in yyyy-mm-dd format)
type (Records the type of document Ex. 1,2,3,etc.)
Number (Records the serial number of a particular type of document)

Now I want to generate a table where I want to order data by timestamp. Based on type I want to display some columns to the left side and some to the right side of the report. So, I want to order my result set to be first ordered by timestamp and then order by type. Say I want 1,2,3 on the left side and 4,5,6 on the right side. So what I want in my resultset is there must be alternate rows of left and right side. Ex.

Timestamp                     Type 
2012-01-01                      1
2012-01-01                      4
2012-01-01                      1
2012-01-01                      4
2012-01-01                      1
2012-01-01                      5
2012-01-01                      1
2012-01-01                      6
2012-01-01                      2
2012-01-01                      2
2012-01-01                      2

I tried to do this but didn't get the desired result. This is the final result I want -

Timestamp        Type        Timestamp        Type
2012-01-01        1            2012-01-01        4
2012-01-01        1            2012-01-01        4
2012-01-01        1
2012-01-02        2            2012-01-02        6
2012-01-02        2            2012-01-02        6
                                        2012-01-03         5
                                         2012-01-03         5
                                        2012-01-03         5

You don't need to sort, if you just collect all the HTML code generated by PHP in two variables ($leftHtml, $rightHtml) while iterating through the result set.

When finished, you echo the entire html in one go in to the right spots. Doesn't matter then, how the rows are sorted (As long as you don't want them sorted by time for instance).

NB: "Timestamp" as well as "type" as a column name will lead to errors on the long run as these are reserved words.

Pseudo Code:

$left = "";
$right = "";
foreach ( $result as $row )
{
  if ( $row['type'] == '1' )
       $left .= "<p>left: " . $row['timestamp'];

  if ( $row['type'] == '2' )
       $right.= "<p>right: " . $row['timestamp'];
}

echo "<table><tr><td>" . $left . "</td><td>" . $right. "</td></tr></table>";

If you want you can do your query like this. What it is doing is saying if the type is either 1, 2, or 3 then the Side = 1 (left) otherwise Side = 2 (right).

SELECT 
    `S.No.`, `Timestamp`, `Type`, `Number`, 
    IF(`Type` IN (1,2,3), 1, 2) as `Side`
FROM `Table`
ORDER BY `Side`, `Timestamp`, `Type`

Since we've ordered by Side we can do this:

<?php
$leftSide = true;
echo '<div class="left-side">';
while ($row = mysqli_fetch_assoc($result)) {
    if ($leftSide && $row['Side'] == 2) {
        // We've hit our first right side row so close the left side div and 
        // start theright side div
        echo '</div><div class="right-side">';
        $leftSide = false;
    }

    // Do something with the row data here
}
echo '</div>';