List Records by Additional Selection

5 posts by 3 authors in: Forums > CMS Builder
Last Post: November 17, 2016   (RSS)

By ross - November 10, 2016

Hi there.

Thanks for posting.

You can combine your two "where" with an "AND" like this:

'where'       => " category LIKE '%Superfast Broadband%' AND uk_network_availability LIKE '%Significant National Coverage%' ",

Could you give that a shot and 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/

By mark99 - November 14, 2016

Yes that worked, brilliant! :)

Now what if I wanted to get a bit more complicated with it and display all the records for 'uk_network_availability' that matched either 'Significant National Coverage' OR 'Patchy National Coverage'?

I tried doing this:

AND uk_network_availability LIKE '%Significant National Coverage%' OR '%Patchy National Coverage%'

But it still only saw the records with 'Significant National Coverage' selected and ignored those with 'Patchy National Coverage' selected.

Hey Mark, 

You  just need to tweek your MySQL statement slightly:

`category` LIKE '%Superfast Broadband%' AND (`uk_network_availability` LIKE '%Significant National Coverage%' OR `uk_network_availability` LIKE '%Patchy National Coverage%' )

There where the two issues:

  • You must declare the field you're searching each time, or the second part of the statement will be ignored. 
  • You should wrap the OR statement in brackets, or you'll end up with all records that have significant national coverage, and then all records that have a category of superfast broadband and significant national coverage. 

Cheers,

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By mark99 - November 17, 2016

Perfect, that fixed it, although I had to remove the ' around uk_network_availability in order to make it work, otherwise no records were displayed. Thanks so much Greg.