brax23 Posted August 5, 2008 Share Posted August 5, 2008 I'm pretty new to php so please bear with me. I've searched the forums for this but can't quite get a grip on it. I'm attempting to display a table with the first column sorted by values in the 'client_project_number' field. I have the 'id' field set as primary key so right now when the table is displayed it is sorted by the values in the 'id' field. How can I sort the displayed table using the 'client_project_number' field instead of the 'id' field? Typical values in the 'client-project-number' filed would be something like ('08-1560-E', '07-3624-E', '02-269-E', etc.). Heres the code I'm using: <?php $result = mysql_query("SELECT * FROM mps_data"); ?> <table border="1"> <tr> <td>Project Number</td> <td>Project Name</td> </tr> <?php while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td><a href='client/index.php?table=".$row['client_project_number']."'>".$row['client_project_number']."</a></td>"; echo "<td><a href='client/index.php?table=".$row['client_project_number']."'>".$row['client_project_name']."</a></td>"; echo "</tr>"; } ?> </table> </body> </html> <?php } } } else { header('Location: login.php'); } ?> Link to comment https://forums.phpfreaks.com/topic/118269-sort-issue/ Share on other sites More sharing options...
niranjnn01 Posted August 5, 2008 Share Posted August 5, 2008 Hello, If i understood your requirement correctly, you should be using the following query select * from mps_data order by `client_project_number` asc this will give you a result set, that is sorted in ascending order with respect to the field `client_project_number` Rakesh Link to comment https://forums.phpfreaks.com/topic/118269-sort-issue/#findComment-608623 Share on other sites More sharing options...
brax23 Posted August 5, 2008 Author Share Posted August 5, 2008 Thank you niranjnn01, worked like a charm. Link to comment https://forums.phpfreaks.com/topic/118269-sort-issue/#findComment-608627 Share on other sites More sharing options...
brax23 Posted August 5, 2008 Author Share Posted August 5, 2008 Thanks Link to comment https://forums.phpfreaks.com/topic/118269-sort-issue/#findComment-608635 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.