user2089016 user2089016 - 1 year ago 157
MySQL Question

how do I insert a horizontal rule between php Sorting

I have no idea where to even start on this. I have code that is selecting data and ordering it based off of two columns.

<?php // Query member data from the database and ready it for display
$sql1 = mysql_query("SELECT id, Name, Age, Rank, Ring, Time FROM competitors ORDER BY Time ASC, Ring + 0 ASC");
while($row1 = mysql_fetch_array($sql1)){
$name =$row1["Name"];
$age =$row1["Age"];
$rank=$row1["Rank"];
$ring1=$row1["Ring"];
$time1=$row1["Time"];
?>


it then displays the data and sorts is based off of the two columns

<?php echo $time1; echo $ring1; ?>


it will display something such as this (yes I know the code I posted doesn't actually display this, but its just a concept)

ring time

1 10:00

1 10:00

1 10:00

1 11:00

1 11:00

1 11:00

I would like to know how I can make it insert a horizontal rule after the first sort by is completed. so it would look something more like this:

1 10:00

1 10:00

1 10:00




1 11:00

1 11:00

1 11:00

and if there were any additional sorts, it would show after each sort is completed as well.
Any advice on this?

Answer Source

Keep track of the last $time1 and when it changes, insert the <hr>

$lastTime = null;
while (/* whatever */) {
    // snip

    // check for null so as not to insert an <hr> for the first record
    if ($lastTime != null && $lastTime != $time1) {
        echo '<hr>';
    }
    $lastTime = $time1;

    // and so on
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download