Stuart Felenstein wrote:
Question - I'm creating a dynamic query (using PHP)
but my question I think is more related to mysql
syntax.
Right now I have these statements:
<?php
$sql .= " SELECT PostStart, JobTitle, Industry,
LocationState, VendorID FROM VendorJobs";
if ($s_Ind){
$sql .= " WHERE VendorJobs.Industry IN ($s_Ind)";
}
if ($s_State){
$sql .= " AND VendorJobs.LocationState IN ($s_State)";
}
What I think I need is some kind of default "WHERE" in
the first statement. Both Ind and State are
conditional based on whether the user input anything.
Right now they would be forced to at least choose the
Ind. So instead of the $s_Ind have a "WHERE" it
should be an "AND" .
??Any thoughts / ideas.
Thank you
Stuart
What I tend to do in this situation is have a WHERE array:
$sql .= " SELECT PostStart, JobTitle, Industry,
LocationState, VendorID FROM VendorJobs";
$aWHERE = array();
if(isset($s_Ind)) $aWHERE[] = "VendorJobs.LocationState IN ($s_Ind)"
if(isset($s_State)) $aWHERE[] = "VendorJobs.LocationState IN ($s_State)"
if(!empty($aWHERE)) $sql .= 'WHERE '.implode(' AND ',$aWHERE);
Chris
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]