hazz995 Posted January 29, 2010 Share Posted January 29, 2010 Trying to sort a table out by certain tags, like username, date registered and member type... No matter how many times I click the links the data wont sort, I had it working with only sorting 2 table columns but it broke when I attempted to add a 3rd. This is the code that starts the sort of, it works by extracting the sort variable from the url then using it to decide what column is being sorted, unfortunately it does not work. <?php $sort = $_GET['sort']; $connect=mysql_connect("localhost","root","root") or die("Could not connect"); mysql_select_db("dbmembers") or die("Could not find database"); if ($sort=0) {$query = "SELECT * FROM users ORDER BY date";} if ($sort=1) {$query = "SELECT * FROM users ORDER BY username";} if ($sort=2) {$query = "SELECT * FROM users ORDER BY admin";} echo "<center><table width=100% style=padding:5;><tr><td><b><a href='?sort=0'>Username</a></b></td><td><b><a href='?sort=1'>Date Registered</a></b></td> <td><b><a href='?sort=2'>Type</a></b></td>"; //Rest of table code... ?> Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/190257-sort-table/ Share on other sites More sharing options...
akitchin Posted January 29, 2010 Share Posted January 29, 2010 your conditions are incorrectly written: if ($sort=0) you're evaluating whether $sort=0 is true. it always will be, since you're just checking whether $sort can be successfully assigned a value of 0. if you want to COMPARE the values, you need to use two equal signs. read up in the PHP manual on operators. Quote Link to comment https://forums.phpfreaks.com/topic/190257-sort-table/#findComment-1003793 Share on other sites More sharing options...
hazz995 Posted January 29, 2010 Author Share Posted January 29, 2010 your conditions are incorrectly written: if ($sort=0) you're evaluating whether $sort=0 is true. it always will be, since you're just checking whether $sort can be successfully assigned a value of 0. if you want to COMPARE the values, you need to use two equal signs. read up in the PHP manual on operators. *facepalm* It completely slipped my mind... Thanks Quote Link to comment https://forums.phpfreaks.com/topic/190257-sort-table/#findComment-1003797 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.