chriscloyd Posted January 11, 2007 Share Posted January 11, 2007 Im trying to make a link where people can order their mysql query fromheres my links[code]<a href="?sort=id">ID</a> <a href="?sort=first, last">Name</a> <a href="?sort=position">Position</a> <a href="?sort=email">Email</a> <a href="?sort=level">Level</a> - <a href="?type=ASC">ASC</a> <a href="?type=DESC">DESC</a>[/code]heres my code[code]<?phpif ($_GET['sort']) { $sort = $_GET['sort']; } else { $sort = 'id'; } if ($_GET['type']) { $type = $_GET['type']; } else { $type = 'ASC'; } $get_all_staff = mysql_query("SELECT * FROM users WHERE level IN('admin','support','sales','staff') ORDER BY '$sort' '$type'");?>[/code] Quote Link to comment Share on other sites More sharing options...
DarkendSoul Posted January 11, 2007 Share Posted January 11, 2007 Well... what error are you getting? Not sorting? You just told us what your doing. Not what you want... ;) Quote Link to comment Share on other sites More sharing options...
chriscloyd Posted January 11, 2007 Author Share Posted January 11, 2007 no sorting at all Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 11, 2007 Share Posted January 11, 2007 I don't think this one: <a href="?sort=first, last"> Will work. Can you print out your sql query to see what it looks like?You have one link for sort and one for type - but no link to do both at the same time. Quote Link to comment Share on other sites More sharing options...
emehrkay Posted January 11, 2007 Share Posted January 11, 2007 change a few things about your approach.first: instead of directly inputting the $_GET var in your query use a switch case so that a user couldnt modify the link to sort=or1=1 - which would show all of your table info<a href="link.php?sort=positon">position</a>then on your processing page do thisswitch($_GET['sort']){case 'position' :$sort = 'position';break;default:$sort = 'id';break;}second:seperate your query from the mysql comman, this will make it easier to tell what the problem is$query = "select...";mysql_query($query) or die (mysql_error()."<br />".$query);third:i like to concatenate my strings$query = "SELECT field FROM table WHERE field = ". $var ." AND ...";that makes it a lil easier to read, espically if you have an editor that will color yoru code Quote Link to comment 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.