Problem with where clause...

5 posts by 2 authors in: Forums > CMS Builder
Last Post: September 9, 2014   (RSS)

By kitka - September 9, 2014

I am having a bit of problem if someone could suggest...

I am trying to get  a listing to display in multiple areas,  fOR INSTANCE A SIMILAR LISTING TO APPEAR ON MULTIPLE PAGES.

Here is a sample per example.

http://www.economyequipmentsales.com/construction-equipment.php

 As an example   From the page example  i want to have  ...beuthling Vibratory Roller

CDN $7,000.00 appear not only in the construction equipMEnt page but also on the turf and agriculture  page as well...

WHEN YOU ADD A NEW LISTINGS  in my options was created 3 categoIies with dropdowns with page  options  where they can decide where the listing is to appear...

  Equipment Type    ( select  from  turf, construction equip, munnicpal agricuture ) etc etc

  Additional Equipment Type 1  

  Additional Equipment Type 2   

THE PROBLEM I AM HAVING IS THAT ONLY  EQUIPMENT TYPE AND EQUIPMENT TYPE 2 ARE shong up on the pages....   ADDITIONAL EQUIPMENT TYPE 1 SELECTIONS ARE NOT BEING SHOWN ON THE PAGES....

ONLY THE LISTINGS SELECTRED FROM EQUIPMENT TYPE AND ADDITIONAL EQUIPMENT TYPE 2.

THE CODE I AM USING IS BELOW AND I SUSPECT I HAVE SOMETHING WRONG IN THERE.  )OR WHERE CLASUE) CAN ANYONE MAKE A SUGGESTION?

HERE IS THE SAMPLE TOP VIEWER CODE FROM THE MUNICIPAL EQUIPMENT PAGE....

<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php
/* STEP 1: LOAD RECORDS - Copy this PHP code block near the TOP of your page */

// load viewer library
$libraryPath = 'cmsAdmin/lib/viewer_functions.php';
$dirsToCheck = array('/home/glenfinbow2014/economyequipmentsales.com/','','../','../../','../../../');
foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }

// load records from 'equipment_for_sale'
list($equipment_for_saleRecords, $equipment_for_saleMetaData) = getRecords(array(
'tableName' => 'equipment_for_sale',
'where' => "equipment_type = 'municipal equipment'",
'orWhere' => "additional_equipment_type_1 = 'municipal equipment'",
'orWhere' => "additional_equipment_type_2 = 'municipal equipment'",

'loadUploads' => true,
'allowSearch' => false,
));?>

jim albert

By claire - September 9, 2014

Hi Kitka

The problem you're having here is that you're basically overriding the first 'orWhere' variable. Here's your getRecords function:

// load records from 'equipment_for_sale'
list($equipment_for_saleRecords, $equipment_for_saleMetaData) = getRecords(array(
'tableName' => 'equipment_for_sale',
'where' => "equipment_type = 'municipal equipment'",
'orWhere' => "additional_equipment_type_1 = 'municipal equipment'",
'orWhere' => "additional_equipment_type_2 = 'municipal equipment'",

'loadUploads' => true,
'allowSearch' => false,
));

That second 'orWhere' overrides the first one, so that it's as if you wrote it like this:

// load records from 'equipment_for_sale'
list($equipment_for_saleRecords, $equipment_for_saleMetaData) = getRecords(array(
'tableName' => 'equipment_for_sale',
'where' => "equipment_type = 'municipal equipment'",
'orWhere' => "additional_equipment_type_2 = 'municipal equipment'",

'loadUploads' => true,
'allowSearch' => false,
));

These things are not cumulative, unfortunately. You can only assign the various options for getRecords once - so only one 'where', only one 'orWhere', only one 'tableName', etc. So - you'll need to modify the getRecords query into something like this, combining the two:

// load records from 'equipment_for_sale'
list($equipment_for_saleRecords, $equipment_for_saleMetaData) = getRecords(array(
'tableName' => 'equipment_for_sale',
'where' => "equipment_type = 'municipal equipment'",
'orWhere' => "(additional_equipment_type_1 = 'municipal equipment' OR additional_equipment_type_2 = 'municipal equipment')",

'loadUploads' => true,
'allowSearch' => false,
));

This should get both equipment types showing up. I'm not 100% sure how you want the logic to work here.

Let me know if this works.

--------------------

Claire Ryan
interactivetools.com

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

By claire - September 9, 2014

No bother :P sorry I didn't get to this sooner, I might have saved you some time!

Let us know if you need any more help.

--------------------

Claire Ryan
interactivetools.com

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

By kitka - September 9, 2014

that's alright...

always good to learn something new each day....

thank you for looking into this for me... Always appreciated....

Have a  great night

JIM

jim albert