stumped by "order by"
| From: | Stuart Felenstein | Date: | Sun, 19 Dec 2004 13:46:20 +0000 |
| Subject: | stumped by "order by" | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-37753@lists.php.net to get a copy of this message | ||
My problem is I can't seem to find the right place to
put an "order by" clause in my statement.
I have this select statement:
$query_rsVJ = " SELECT Jobs.PostStart,
Jobs.JobID,Jobs.JobTitle,
Jobs.City, Ind.Categories, VendorSignUp.CompanyName,
US.States, Term.Tax FROM Jobs
INNER JOIN Ind ON (Jobs.Industry = Ind.CIDs)
INNER JOIN US ON (Jobs.State = US.SID)
INNER JOIN SignUp ON (Jobs.VID = SignUp.VID)
INNER JOIN Term ON (Jobs.Tax = Term.TID)";
But then I also have a dynamic where clause that is
based on what values the user has chosen:
if(!empty($s_Ind)) $aWHERE[] = "Jobs.Industry IN
($s_Ind)" ;
if(!empty($s_State)) $aWHERE[] = "Jobs.State IN
($s_State)";
if(!empty($s_TType)) $aWHERE[] = "Jobs.Term IN
($s_TType)";
if(!empty($JTitle)) $aWHERE[] = "Jobs.Title LIKE
'%$JTitle%'";
if(!empty($City)) $aWHERE[] = "Jobs.City LIKE
'%$City%'";
if(!empty($Days)) $aWHERE[] = "Jobs.Post >=
DATE_SUB(CurDate(), Interval ($Days) DAY)";
When the sql is submitted the results come back (in
columns of course) Then the user can click the column
head and sort by that column.
$orderParam_rsVJ = "City";
if (isset($_GET['order_rsVJ'])) {
$orderParam_rsVJ = (get_magic_quotes_gpc()) ?
$_GET['order_rsVJ'] : addslashes($_GET['order_rsVJ']);
}
I just have had no luck putting in
order by "$orderParam_rsVJ in the current statement
(above).
If I put it in the select statement , the it's out of
place with the where clause.
If I put it at the end of the where clause, obviously
it is not seen.
Any ideas how I can set this up correctly ?
Stuart