if else question
3 posts by 2 authors in: Forums > CMS Builder
Last Post: May 2, 2012 (RSS)
By Rohwer - May 2, 2012 - edited: May 2, 2012
I have a search results page that is pulling in variable family via query string.
ie. ?family=Cruiser
I am making a page that I want to be able to show results from multiple family types.
ie. Cruiser, Dirtbike, Sportbike etc (OR Statements)
Below is the code I have been working with. What am I missing?
motorcycles is the variable i am pulling in to set off the if statement.
Thank you community/admins in advance!!
ie. ?family=Cruiser
I am making a page that I want to be able to show results from multiple family types.
ie. Cruiser, Dirtbike, Sportbike etc (OR Statements)
Below is the code I have been working with. What am I missing?
$motorcycles=@$_GET['family'];
if($motorcycles=="motorcycle")
list($newvehiclesRecords, $newvehiclesMetaData) = getRecords(array(
'tableName' => 'newvehicles',
'where' => 'active = \'1\' and newused = \'Used\' AND (family = \'Cruiser\' or family = \'Dirtbike\' or family = \'Sportbike\' or family = \'Touring\' or family = \'Trikes\')' ,
'perPage' => $perPage,
'orderBy' => $order,
));
else
list($newvehiclesRecords, $newvehiclesMetaData) = getRecords(array(
'tableName' => 'newvehicles',
'where' => 'active = \'1\' and newused = \'Used\'',
'perPage' => $perPage,
'orderBy' => $order,
));
motorcycles is the variable i am pulling in to set off the if statement.
Thank you community/admins in advance!!
Re: [Rohwer] if else question
By Jason - May 2, 2012
Hi,
Since "family" is a field name in your newvehicles section, getRecords is automatically adding it to your WHERE clause. To stop this you can use the "allowSearch" => false, option like this:
NOTE: I also changed your query to use the mysql IN clause. It just helps the code be a little easier to read:
Give this a try and let me know if this gives you the results you are looking for.
Thanks,
Since "family" is a field name in your newvehicles section, getRecords is automatically adding it to your WHERE clause. To stop this you can use the "allowSearch" => false, option like this:
NOTE: I also changed your query to use the mysql IN clause. It just helps the code be a little easier to read:
$motorcycles = @$_GET['family'];
if($motorcycles == "motorcycle") {
list($newvehiclesRecords, $newvehiclesMetaData) = getRecords(array(
'tableName' => 'newvehicles',
'where' => "active = '1' and newused = 'Used' AND family IN('Cruiser', 'Dirtbike', 'Sportbike', 'Touring','Trikes')" ,
'allowSearch' => false,
'perPage' => $perPage,
'orderBy' => $order,
));
}
else {
list($newvehiclesRecords, $newvehiclesMetaData) = getRecords(array(
'tableName' => 'newvehicles',
'where' => "active = '1' and newused = 'Used'",
'allowSearch' => false,
'perPage' => $perPage,
'orderBy' => $order,
));
}
Give this a try and let me know if this gives you the results you are looking for.
Thanks,
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
Re: [Jason] if else question
By Rohwer - May 2, 2012 - edited: May 2, 2012
You sir.... rock.
Just had to remove the 'allowSearch' => false, in the else portion.
because this page only has that one exception.
Much appreciated!
Just had to remove the 'allowSearch' => false, in the else portion.
because this page only has that one exception.
Much appreciated!