note 88862 added to control-structures.switch

From: Date: Wed, 11 Feb 2009 14:51:59 +0000
Subject: note 88862 added to control-structures.switch
Groups: php.notes 
Request: Send a blank email to php-notes+get-150486@lists.php.net to get a copy of this message
ok here's an odd one, I'm running a query with php through an ODBC conn , using SQL Statements. I'm kinda new to switch statements, and have come up with the following: <?php if (!isset ($_GET['order']) { $order = $default_sort; } $Conn = odbc_connect("dsn","user","pass") or die("error:.odbc_errormsg()); echo "<table> <th align=\"left\" scope=\"col\" class=\"style2\">Incident Number</th> <th align=\"left\" scope=\"col\" class=\"Style2\">Assignee</th> <th align=\"left\" scope=\"col\" class=\"Style2\">Date</th> <th align=\"left\" scope=\"col\" class=\"Style2\">Description</th>"; Switch($order) { Case 'default_sort': $Query = "SELECT "Help_Desk.Incident_Number," . "Help_Desk.Assignee," . "Help_Desk.Reported_Date," . "Help_Desk.Description," . "Where (Help_Desk.Group='TAC') ORDER BY $default_order; Case 'Assignee': $Query = "SELECT "Help_Desk.Incident_Number," . "Help_Desk.Assignee," . "Help_Desk.Reported_Date," . "Help_Desk.Description," . "Where (Help_Desk.Group='TAC') ORDER BY 'Assignee'; Case 'Date': $Query = "SELECT "Help_Desk.Incident_Number," . "Help_Desk.Assignee," . "Help_Desk.Reported_Date," . "Help_Desk.Description," . "Where (Help_Desk.Group='TAC') ORDER BY 'Reported_Date'; Case 'Description': $Query = "SELECT "Help_Desk.Incident_Number," . "Help_Desk.Assignee," . "Help_Desk.Reported_Date," . "Help_Desk.Description," . "Where (Help_Desk.Group='TAC') ORDER BY 'Description'; } $Result = odbc_exec($Conn,$Query) or die("Failed to execute query."); $OddRow = true; while(odbc_fetch_row($Result)) $Incident_Number = odbc_result($Result,1); $Assignee = odbc_result($Result, 2); $Reported_Date = odbc_result($Result,3); $Description = odbc_result($Result,4); if($OddRow == true) $Class = "style3"; else $Class = "style4"; $OddRow = !$OddRow; echo "<tr> <td class=\"$Class\">$Incident_Number</td> <td class=\"$Class\">$Status</td> <td class=\"$Class\">$Assignee</td> <td class=\"$Class\">$Description</td> </tr>"; $Count++; } ?> Currently the code outputs the table in asc order by Incident_Number. What I'm trying to accomplish is to be able to click on a hyperlink at the column heading, and sort the data in the rows by that column, I.e, be able to click on Assignee and have the data sorted by name. I know i can do this w/o resorting to some java script. I also don't mind that clicking on the link will reload the entire data/page. Also the page auto refreshes it self, and I would like for it to refresh to the last column header selected. ---- Server IP: 209.41.74.194 Probable Submitter: 166.102.1.135 ---- Manual Page -- http://www.php.net/manual/en/control-structures.switch.php Edit -- https://master.php.net/note/edit/88862 Del: integrated -- https://master.php.net/note/delete/88862/integrated Del: useless -- https://master.php.net/note/delete/88862/useless Del: bad code -- https://master.php.net/note/delete/88862/bad+code Del: spam -- https://master.php.net/note/delete/88862/spam Del: non-english -- https://master.php.net/note/delete/88862/non-english Del: in docs -- https://master.php.net/note/delete/88862/in+docs Del: other reasons-- https://master.php.net/note/delete/88862 Reject -- https://master.php.net/note/reject/88862 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#150486) next »