triphis Posted September 29, 2003 Share Posted September 29, 2003 I was wondering how I can reorder the MySQL query \"order by\" with the use of forms. I have no clue. My friend owns this site, but because she knows ASP, rather than PHP, she was unable to help me. http://neoguide.dcwd.biz/Pet.asp See all the buttons? By clicking on them, the list order is changed. Quote Link to comment Share on other sites More sharing options...
DylanBlitz Posted September 29, 2003 Share Posted September 29, 2003 you\'d want to pass a variable to the page and have that variable tell what query to run. Something like [php:1:74ec0ffbbe]<?php if ($_REQUEST[submitted] == \"true\") { $sort = $_POST[\'sort\']; if ($sort == \"name\") { $query = mysql_query(\"select user_id, user_name, user_address, user_type from table ORDER BY user_name\"); } elseif ($sort == \"address\") { $query = mysql_query(\"select user_id, user_name, user_address, user_type from table ORDER BY user_address\"); } elseif ($sort == \"type\") { $query = mysql_query(\"select user_id, user_name, user_address, user_type from table ORDER BY user_type\"); } else { $query = mysql_query(\"select user_id, user_name, user_address, user_type from table ORDER BY user_id\"); } } ?> <FORM ACTION=\"<?= $_SERVER[\"PHP_SELF\"] ?>\" METHOD=\"post\"> <SELECT NAME=\"sort\"> <OPTION SELECTED VALUE=\"name\">User Name <OPTION VALUE=\"address\">User Address <OPTION VALUE=\"type\">User Type </SELECT> </FORM> [/php:1:74ec0ffbbe] That\'s how I\'d do it anyway Quote Link to comment Share on other sites More sharing options...
triphis Posted September 29, 2003 Author Share Posted September 29, 2003 thank you that makes a whole lotta sense >.> *is daft* Quote Link to comment Share on other sites More sharing options...
triphis Posted September 29, 2003 Author Share Posted September 29, 2003 Hey, if I wanted to shorten this: [php:1:d805344b15]<?php if ($sort == \"name\") { $query = mysql_query(\"select user_id, user_name, user_address, user_type from table ORDER BY user_name\"); } elseif ($sort == \"address\") { $query = mysql_query(\"select user_id, user_name, user_address, user_type from table ORDER BY user_address\"); } elseif ($sort == \"type\") { $query = mysql_query(\"select user_id, user_name, user_address, user_type from table ORDER BY user_type\"); } else { $query = mysql_query(\"select user_id, user_name, user_address, user_type from table ORDER BY user_id\"); } ?>[/php:1:d805344b15] I could go like this right? : [php:1:d805344b15] $query = mysql_query(\"select user_id, user_name, user_address, user_type from table \"); if ($sort == \"name\") { $query .= ORDER BY user_name; } elseif ($sort == \"address\") { $query .= ORDER BY user_address; } elseif ($sort == \"type\") { $query .= ORDER BY user_type; } else { $query .= ORDER BY user_id\"); } [/php:1:d805344b15] I don\'t know the correct use of \" .= \" but I know it adds to a previous variable. 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.