Jump to content

Sort Issue


brax23

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.