hey guys,
i have a mysql table of tasks with fields for id, name, comments, priority, status(incomplete, complete), etc.. i am using php to output a list of the tasks and their attributes. i would like to able to sort them by name, date, priority, status, etc... so this is an excerpt of what i have set up.
html select to determine sort key.
and php to grab the sort key and inject into mysql query.
while it appears that i am using a valid sql query, it doesnt seem to work... does anyone see something that im not catching that would cause this not to work.
thanks for your help.
oh by the way, the value fields for each select option are identical to the column names in my table with the exception of the -1 or -2. for example
would explode to "priority_code" (the name of the priority column in my table) and "1" which is used to determine ASC or DESC in the sql query.
i have a mysql table of tasks with fields for id, name, comments, priority, status(incomplete, complete), etc.. i am using php to output a list of the tasks and their attributes. i would like to able to sort them by name, date, priority, status, etc... so this is an excerpt of what i have set up.
html select to determine sort key.
HTML:
<select name="s" id="s">
<option value="">--</option>
<option value="name-1">[ASC] Task Name</option>
<option value="name-2">[DSC] Task Name</option>
<option value="">--</option>
<option value="priority_code-1">[ASC] Priority</option>
<option value="priority_code-2">[DSC] Priority</option>
<option value="status_code-1">[ASC] Status</option>
<option value="status_code-2">[DSC] Status</option>
</select>
and php to grab the sort key and inject into mysql query.
PHP:
if(isset($_GET['s'])&&$_GET['s']!="") {
$s=explode("-",$_GET['s']);
$sortkey=$s[0];
$order=$s[1];
if($order==1) {
$gettasks_resc=mysql_query("SELECT * FROM tasks ORDER BY '$sortkey' ASC");
} elseif($order==2) {
$gettasks_resc=mysql_query("SELECT * FROM tasks ORDER BY '$sortkey' DESC");
} else {
$gettasks_resc=mysql_query("SELECT * FROM tasks ORDER BY name ASC");
}
} else {
$gettasks_resc=mysql_query("SELECT * FROM tasks ORDER BY name ASC");
}
while it appears that i am using a valid sql query, it doesnt seem to work... does anyone see something that im not catching that would cause this not to work.
thanks for your help.
oh by the way, the value fields for each select option are identical to the column names in my table with the exception of the -1 or -2. for example
HTML:
<option value="priority_code-1">