> -----Original Message----- > From: Stuart Felenstein [mailto:[EMAIL PROTECTED] > Sent: Sunday, November 14, 2004 11:30 AM > To: [EMAIL PROTECTED] > Subject: Conditonal where > > <?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" .
You could add a where condition that's always true to the main part of the SQL statement so that you can just tack on more clauses conditionally. $sql .= "SELECT PostStart, JobTitle, Industry, LocationState, VendorID " . "FROM VendorJobs" . "WHERE 1 = 1 "; if ($s_Ind) { $sql .= "AND VendorJobs.Industry IN ($s_Ind) "; } if ($s_State) { $sql .= " AND VendorJobs.LocationState IN ($s_State)"; } -- Pat Adams Applications Programmer SYSCO Food Services of Dallas, L.P. (469) 384-6009 -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]