Re: MultSelect ListBox hell!
| From: | Doug Thompson | Date: | Wed, 22 Sep 2004 13:11:03 +0000 |
| Subject: | Re: MultSelect ListBox hell! | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-36326@lists.php.net to get a copy of this message | ||
Stuart Felenstein wrote:
I am in the process of building a search form for the database. The entire thing consists of 3 multi selects and 2 text boxes with a "contains". Oh and I've only rigged 2 of the multi selects for the time being. So the way the multiselects should work that the user can choose one or the other or both, but the more criteria provided back to the query , the more refined the return. Here is the code and my tale of woe follows:($projects is a just a holder / variable) function BindEvents() {You need LocationState to be, in your example, Alabama OR California. Also, I would write that SQL phrase "LocationState = 'Alabama' OR LocationState='California' ". Doug Dougglobal $VendorJobs; $VendorJobs->ds->CCSEvents["BeforeExecuteSelect"]= "VendorJobs_ds_BeforeExecuteSelect"; } //End BindEvents Method //VendorJobs_ds_BeforeExecuteSelect @2-A4F75E44 function VendorJobs_ds_BeforeExecuteSelect() {$VendorJobs_ds_BeforeExecuteSelect = true;//End VendorJobs_ds_BeforeExecuteSelect global $VendorJobs; $s_Industry = CCGetParam("s_Industry", ""); if (count($s_Industry) > 0 AND is_array($s_Industry)) { foreach ($s_Industry as $key => $value) { if ($Projects != "") $Projects = $Projects.","; $Projects = $Projects."'".$value."'"; } } if ($Projects) $VendorJobs->ds->SQL.= " AND (VendorJobs.Industry IN (".$Projects."))"; $s_LocationState = CCGetParam("s_LocationState", ""); if (count($s_LocationState) > 0 AND is_array($s_LocationState)) { foreach ($s_LocationState as $key => $value) { if ($Projects != "") $Projects = $Projects.","; $Projects = $Projects."'".$value."'"; } } if ($Projects) $VendorJobs->ds->SQL.= " AND (VendorJobs.LocationState IN (".$Projects."))"; echo "SQL:". $VendorJobs->ds->SQL."<br>"; return $VendorJobs_ds_BeforeExecuteSelect; If you notice in the the SQL the "AND", I've changed them back and forth to OR and a combo of AND in the first and OR in the second. If I have OR in both, then each multi works on it's own, no refined / results. If I have AND in both, then they come together but if I try to add more values (like a multi select should allow) I get a "no records" return. So something like this using in both AND: I choose from Industry : Accounting and FinanceFrom LocationState: I choose Alabamagreat it gives back to me all accounting and finance records Alabama But if I add in LocationState, Alabama and California then a no records is returned. Anyway, if anyone has some pointers or ideas I'd greatly appreciate. Stuart