Page 1 of 1

Sorting record menu

Posted: Mon Feb 07, 2005 5:23 am
by mhouldridge
Hi,

I have a script which displays the records by "Type", which is the name for that column.

I would like a drop down box to re-sort these by "asset", which is the unique asset number given, so that I can run through everything in order of asset.

Here is the code for the view.php page that shows the records by type;

Code: Select all

<?php
$db = mysql_connect("localhost","giacom-admin","snooker") or die("Problem connecting");
mysql_select_db("audit") or die("Problem selecting database");
$query = "SELECT * FROM dedicated order by type";
$result = mysql_query($query) or die ("Query failed");
//let's get the number of rows in our result so we can use it in a for loop
$numofrows = mysql_num_rows($result);
echo "<TABLE BORDER="0" table width="100%">\n";
echo "<TR bgcolor="#cccccc"><TD font colour="red"><b>Asset</b></TD><TD><b>Title</b></TD><TD><b>Customer</b></TD><TD><b>Type</b></TD><TD><b>IP address</b></TD><TD><b>Location</b></TD><TD><b>OS</b></TD><TD><b>OS License</b></TD></TR>\n";
for($i = 0; $i < $numofrows; $i++) &#123;
    $row = mysql_fetch_array($result); //get a row from our result set
    if($i % 2) &#123; //this means if there is a remainder
        echo "<TR bgcolor="#ffff99">\n";
    &#125; else &#123; //if there isn't a remainder we will do the else
        echo "<TR bgcolor="#ffffcc">\n";
    &#125;
    echo "<TD><font color="red"><b>".$row&#1111;'asset']."</b></font></TD><TD><font size="2">".$row&#1111;'title']."</TD><TD><font size="2">".$row&#1111;'customer']."</TD><TD><font size="2">".$row&#1111;'type']."</TD><TD><font size="2">".$row&#1111;'IP']."</TD><TD><font size="2">".$row&#1111;'location']."</TD><TD><font size="2">".$row&#1111;'os']."</TD><TD><font size="2">".$row&#1111;'oslicense']."</TD>\n";
    echo "</TR>\n";
&#125;
//now let's close the table and be done with it
echo "</TABLE>\n";
?>

feyd | help us help you, use the formatting we provide

Posted: Mon Feb 07, 2005 9:36 am
by feyd
feyd wrote:Dynamic sorting by column header: call "ORDER BY" command from php