johnliverpool Posted August 17, 2011 Share Posted August 17, 2011 Hi all Hope someone can help I would like to list my address's in both numeric and alphabetic order as below: 33 Connaught Rd, Kensington, L18 7HX 69 Connaught Rd, Kensington, L7 8RW 111 Connaught Rd, Kensington, L7 8RW the script I use as follows: $query="SELECT * FROM $useron ORDER BY `address1` ASC"; $result=mysql_query($query); $num=mysql_num_rows($result); if ($num > 0 ){ }; mysql_close(); if ($num > 0 ) { $i=0; while ($i < $num) { $housenum = mysql_result($result,$i,"housenum"); $address1 = mysql_result($result,$i,"address1"); $address2 = mysql_result($result,$i,"address2"); $postcode = mysql_result($result,$i,"postcode"); $status = mysql_result($result,$i,"status"); $id = mysql_result($result,$i,"id"); ?> <table width="850" border="0" style="font-size:12px" > <tr> <th width="350" height="10" scope="col" align="left"><? echo $housenum, " ", $address1, ", ", $address2, ", ", $postcode; ?></th> <th width="150" height="10"scope="col" align="left"> Work Status: <font color="#FF0000"> <?php echo $status; ?></font> <th width="350" height="10"scope="col" align="left"><? echo " <a href=\"update.php?id=$id&useron=$useron\">Update</a> - <a href=\"delete.php?id=$id&useron=$useron\">Delete</a> - <a href=\"workrequest.php?id=$id&useron=$useron\">work request</a>"; if ($status=="Active"){ echo " <a href=\"vwr.php?id=$id&useron=$useron\">View work requested</a>"; } ?> </th> </tr> </table> Lists the address's as below: 111 Connaught Rd, Kensington, L7 8RW Work Status: Idle Update - Delete - work request 33 Connaught Rd, Kensington, L18 7HX Work Status: Idle Update - Delete - work request 69 Connaught Rd, Kensington, L7 8RW Work Status: Idle Update - Delete - work request Any help would be much appreciated, For any advice given thanks, John Quote Link to comment https://forums.phpfreaks.com/topic/245062-how-can-i-list-address-number-and-street-alphanumerically/ Share on other sites More sharing options...
AbraCadaver Posted August 17, 2011 Share Posted August 17, 2011 Try: SELECT * FROM $useron ORDER BY address1+0 ASC Quote Link to comment https://forums.phpfreaks.com/topic/245062-how-can-i-list-address-number-and-street-alphanumerically/#findComment-1258729 Share on other sites More sharing options...
dougjohnson Posted August 17, 2011 Share Posted August 17, 2011 Why not make "sort by" links at the top of each column - housenum, address1, address2, postcode. Clicking on the "sort by" links would sort by the column data. Or, I may have not understood your question? Quote Link to comment https://forums.phpfreaks.com/topic/245062-how-can-i-list-address-number-and-street-alphanumerically/#findComment-1258730 Share on other sites More sharing options...
xyph Posted August 17, 2011 Share Posted August 17, 2011 Is the housenum column an integer type? or varchar? If it's an integer type, use SELECT `cols` FROM `table` ORDER BY `address1`, `housenum` Quote Link to comment https://forums.phpfreaks.com/topic/245062-how-can-i-list-address-number-and-street-alphanumerically/#findComment-1258731 Share on other sites More sharing options...
johnliverpool Posted August 18, 2011 Author Share Posted August 18, 2011 Try: SELECT * FROM $useron ORDER BY address1+0 ASC This did'nt work thanks though Quote Link to comment https://forums.phpfreaks.com/topic/245062-how-can-i-list-address-number-and-street-alphanumerically/#findComment-1258936 Share on other sites More sharing options...
johnliverpool Posted August 18, 2011 Author Share Posted August 18, 2011 Why not make "sort by" links at the top of each column - housenum, address1, address2, postcode. Clicking on the "sort by" links would sort by the column data. Or, I may have not understood your question? I know what your saying but would like house num and address alphanumerically listed from the start, thanks for reply Quote Link to comment https://forums.phpfreaks.com/topic/245062-how-can-i-list-address-number-and-street-alphanumerically/#findComment-1258937 Share on other sites More sharing options...
johnliverpool Posted August 18, 2011 Author Share Posted August 18, 2011 Is the housenum column an integer type? or varchar? If it's an integer type, use SELECT `cols` FROM `table` ORDER BY `address1`, `housenum` They are set as varchar but can change if you can give me more info. Quote Link to comment https://forums.phpfreaks.com/topic/245062-how-can-i-list-address-number-and-street-alphanumerically/#findComment-1258938 Share on other sites More sharing options...
johnliverpool Posted August 18, 2011 Author Share Posted August 18, 2011 Is the housenum column an integer type? or varchar? If it's an integer type, use SELECT `cols` FROM `table` ORDER BY `address1`, `housenum` Thanks xyph, "SELECT * FROM $useron ORDER BY address1, housenum ASC"; this worked Quote Link to comment https://forums.phpfreaks.com/topic/245062-how-can-i-list-address-number-and-street-alphanumerically/#findComment-1258992 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.