Thank you Sir, now my code fully functional as below. TQVM...
<?php
function v( $value , $option )
{
/ make sure the $option and $value converted to HTML entities /
$value = htmlspecialchars( $value );
$option = htmlspecialchars( $option );
// set the selected tag if you have a selected item
$selected = (isset( $REQUEST["q"]) AND $REQUEST["q"] == $value )?'selected="selected"' : '';
// read more about printf!
printf( "<option value='%s' %s>%s</option>\r" , $value , $selected , $option );
}
?>
<form method="GET" action="<?=$self?>" >
<select id="q" name="q">
<optgroup label="Lorry Info">
<?php
v( 'id' , 'id' );
v( 'Lorry_No' , 'Lorry No' );
v( 'Location' , 'Location' );
v( 'Type' , 'Type' );
?>
<optgroup label="Expiry Date">
<?php
v( 'Road_Tax_Expiry' , 'Road_Tax_Expiry' );
v( 'Puspakom_Expiry' , 'Puspakom_Expiry' );
v( 'Mileage' , 'Mileage' );
?>
</select>
<input type="submit" value="show »" />
</form>
</div>
<?php
$Sortby = isset($REQUEST['q']) ? $REQUEST['q'] : 'id';
mysql_connect("localhost", "warisanm_fleet", "warisan007") or die(mysql_error());
echo "Connected to MySQL<br />";
mysql_select_db("warisanm_fleet") or die(mysql_error());
echo "Connected to Database";
// Get all the data from the "example" table
$result = mysql_query("SELECT * FROM fleet ORDER BY $Sortby")
or die(mysql_error());
echo "<table border='1'>";
echo "<tr> <th>ID</th> <th>Lorry No</th> <th>Trailer No</th> <th>Location</th> <th>Logo No</th> <th>Type</th> <th>Road Tax Expiry</th> <th>Puspakom Expiry</th> <th>Mileage</th> <th>Shell Card Limit</th> <th>Revenue</th> <th>Tyre</th> <th>Maintenance</th> <th>Fuel Consumption</th> <th>Driver Name</th> <th>Remarks</th> </tr>";
// keeps getting the next row until there are no more to get
while ( $row = mysql_fetch_assoc( $result ) ) {
echo '<tr>';
foreach( $row AS $c ) {
printf( '<td>%s</td>' , $c );
}
echo '</tr>';
}
echo "</table>";
?>