[FX.php List] Which is faster?

Leo R. Lundgren leo at finalresort.org
Sat Sep 11 13:13:11 MDT 2010


Pretty much. But using the counter probably isn't necessary. Imagine your checkboxes look like this:

	<input type="checkbox" name="service[__SOME_ID__]">

Then on the recieving side I'd do:

	$query = new SomeGoodQueryClass();
	$query->setLogicalOr();
	if(isset($_POST['service']) && is_array($_POST['service'])) {
		foreach($_POST['service'] as $someId) {
			$query->addParam('someId', $someId);
		}
	}
	$queryResult = $query->execute();

Now, what you use for __SOME_ID__ above should be a unique value from the records, obviously, usually the primary key of the records (be it your own 'ID' field or the recId from FM).


11 sep 2010 kl. 21.02 skrev Bob Patin:

> 
> On Sep 11, 2010, at 1:48 PM, Leo R. Lundgren wrote:
> 
>> Isn't it possible to create one query (in page 2) like the equivalent of SQL's "select foo from bar where id=1 or id=3 or id=4"? I.e. building a query that asks for the IDs that were submitted in the form.
> 
> I haven't tried using the SetLogicalOR() command before; I'll give it a try.
> 
> So I'll just loop through my form POSTs, pulling recids and adding a line to my query for each returned recid; is that how you'd do it? Something like this:
> 
> $counter = $_POST['counter']; // this is the # of items that were on the previous form
> 
> // $_POST['service'] is the recid of the item that was checked
> 
> $query->SetLogicalOR();
> while ($i <= $counter){
> 	if strlen($_POST['service'])>0){
> 		$query->AddDBParam('recid',$_POST['service']);
> 	}
> 	$i++;
> }
> $queryResult = $query->FMFind();
> 
> That would do it, wouldn't it?
> 
> BP
> 
> 
> 
> 
> _______________________________________________
> FX.php_List mailing list
> FX.php_List at mail.iviking.org
> http://www.iviking.org/mailman/listinfo/fx.php_list



-|



More information about the FX.php_List mailing list