Create a "Where" statement by selecting a field already present on the page.

4 posts by 2 authors in: Forums > CMS Builder
Last Post: March 23, 2019   (RSS)

By daniel - March 22, 2019

Hey Andy, 

It's possible that the value in $listingsRecord['property_type'] isn't an integer, and so when you use intval() it doesn't return the correct value for matching. You can try changing intval to mysql_escape to see if that makes any difference. If that doesn't help, I would suggest adding:

'debugSql' => false,

 to the list of arguments in getRecords() and load the page. This will display the full MySQL query being used - if you copy that here I can check to see if there are any other obvious issues with it.

Thanks,

Daniel
Technical Lead
interactivetools.com

By andybarn - March 23, 2019

Thanks Daniel

changing intval to mysql_escape did the trick - fantastic!

One last question on this please?

My "where" statement now reads

    'where' => "property_type ='".mysql_escape($listingsRecord['property_type'])."' AND town='".mysql_escape($listingsRecord['town'])."'", 

This now produces all similar properties based on "property_type" and "town" but it also includes the currently displayed property.

Is there a line I can to the "where" statement that excludes the current listing that is being displayed.?

Thanks again for your great suport.

Andy

By andybarn - March 23, 2019

Hi Daniel

I think I have answered my own question after a bit of delving into the support forum.

I changed my "where" statement by adding one more "AND" statement to exclude current property. For you and those that may be looking for the same thing, my "where" statement is as follows:-

    'where' => "property_type ='".mysql_escape($listingsRecord['property_type'])."' AND town='".mysql_escape($listingsRecord['town'])."' AND num!='".mysql_escape($listingsRecord['num'])."'", 

Thanks again for pointing me in the right direction.

Kind regards

Andy