Call list(...) multiple times in same page...

2 posts by 2 authors in: Forums > CMS Builder
Last Post: September 29, 2011   (RSS)

Hello-

I'm trying to return a relevant set of records from CMSB based on what the user specifies...For example if they click on "Under 1,000,000", I execute this, which resides in a javascript function called "pricegroup1":

<?php
// load records
list($properties_for_saleRecords, $properties_for_saleMetaData) = getRecords(array(
'tableName' => 'properties_for_sale',
'where' => 'list_price<1000000',
'orderBy' => 'list_price DESC',
));
?>

If they click on "1,000,000 to 1,499,999", I WANT to execute this, which resides in another javascript function called "pricegroup2":

list($properties_for_saleRecords, $properties_for_saleMetaData) = getRecords(array(
'tableName' => 'properties_for_sale',
'where' => 'list_price>=1000000 and list_price<1500000',
'orderBy' => 'list_price DESC',
));

It's only when I add the 2nd list() block to my PHP page that things stop working, and my browser says there's a javascript error...no ending semicolon on a line number that doesn't even exist...

If I remove the where clause from the 2nd list() bloc, the js error goes away, but of course, the correct data isn't returned. Also, if I simplify the where clause to 'where' => 'list_price<1500000', the error returns...If I change this to 1000000, the error goes away again...

My question is: Is it legal to have more than 1 list() block on a page....I'm stuck...

I hope this is somewhat clear...

Thanks for the help...Rick

Re: [rcrofoot] Call list(...) multiple times in same page...

By Jason - September 29, 2011

Hi Rick,

The problem here, I think, is the use of javascript. PHP is a server side technology, which means it is executed by the webserver before it ever gets sent to your client's browser. Javascript is a client side technology, so it is executed by the client's browser. So in your script, your PHP statements are being executed before the page is sent to your client.

There isn't a way to have a javascript function that executes PHP on the client side. The closest you can get is to use jQuery, but that still just makes a call to the server to execute the PHP there.

The best approach here, I think, is to have your form refresh you page with each selection, then execute a different getRecords call depending on their selection.

Hope this helps get you started. Please let us know if you run into any difficulties.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/