MySQL Where problem

3 posts by 2 authors in: Forums > CMS Builder
Last Post: April 29, 2015   (RSS)

By gadefgaertgqe - April 22, 2015 - edited: April 22, 2015

Hi,

I have been trying to filter records using the where option, but seem to have hit a wall. I just don't seem to be able to get any results back and have an empty array.

I have an editor list of images. In there I have a drop down for 'Product' (to associate the image with a product) which is populated by using the "Get options from database (advanced)", as I have an editor list of products to easily add and create new products.

// load detail record from 'images'
  list($imagesRecords, $imagesMetaData) = getRecords(array(
    'tableName'   => 'images',
    'where' => "'product:label' = 'Hats and Scarfs'",
    'loadUploads' => true,
    'allowSearch' => false,
  ));

Any suggestions on where I am going wrong?

Thanks

Paul

By ross - April 24, 2015

Hi Paul

Thanks for posting!

I think I understand what you are aiming for.  When you setup the "Product" drop down menu to pull from another database table, you get to specify which table, then which field to store as the value (this is what gets stored in the database) and then which value you to use as the label (this is what gets displayed).

What you'll want to do first is double check what you have set as the "value". I always recommend using the "num" field from your other table so you will want to consider changing it to that if you haven't already.

Next, the code you are looking for will end up looking something like this:

'where' => "product = 1",

notice how there is no quotes around product and I just have a number after the equals.  Because I've got you using the "num" field as the label, you'll just need to make sure which record from the Products table you want to match and use its record number.  

Does that make sense? Let me know how you make out.

Thanks!

-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/