building a query for GetList()

4 views
Skip to first unread message

frobn

unread,
Mar 9, 2006, 8:59:44 AM3/9/06
to Php Object Generator
I am trying to build a query for GetList() with variables from a search
from.

When I build the query
$search=
$search=if($beds){$search= $search.'array("beds","=","'.$beds.'"),';}
$search=if($baths){$search= $search.'array("beds","=","'.$baths.'"),';}

$search when expanded look like this:
array("beds","=","2"),
array("baths","=","2"),

This works:
$listingsList = $listings ->
GetList(array(
array("beds","=","2"),
array("baths","=","2"),
)
,"", true, "$offset,$limit"
);

but when I use $search I get the error: "You have an error in your SQL
syntax"

$listingsList = $listings ->
GetList(array(
$search
)
,"", true, "$offset,$limit"
);

Any ideas?

Thanks,
Frank

Joel

unread,
Mar 9, 2006, 10:45:08 AM3/9/06
to Php Object Generator
Hi Frank,

yes, i think i see your problem. because $search contains not only data
but php directives (in your case "array"), try this:

$listingsList = $listings ->
GetList(array(
{$search}
)
,"", true, "$offset,$limit"
);

or try


eval ("\$listingsList = \$listings ->
GetList(array(".
$search."
)
,\"\", true, \"\$offset,\$limit\"
);";

let me know if this helps

Joel

frobn

unread,
Mar 9, 2006, 1:29:11 PM3/9/06
to Php Object Generator
Thanks Joel,

Your suggestions words. I had to play with it a bit and here is the
resulting code. I am runing the query twice, the first time without the
limit to obtain a count for pagination. I hope this will be helpful to
others.


eval ('
$count= count(


$listingsList = $listings ->
GetList(array(

'.$search.'
)
));

'); //end eval


$page=ceil($count/$limit); //# of pages


eval ('
$listingsList = $listings ->
GetList(array(

'.$search.'


)
,"", true, "$offset, $limit"
);

'); //end eval

Its amazing what can be done with POG. Thank you for making it
available and also for your time,

Frank

Reply all
Reply to author
Forward
0 new messages