Main
Index
Search
Posts
Who's
Online
Log
In

Home: Discontinued/Classic Products: Instant Website: Realty/Listings/Auto:
Filter Using a Checkbox Field

 

 


nprivette
User

Oct 15, 2009, 8:26 PM

Post #1 of 5 (4264 views)
Shortcut
Filter Using a Checkbox Field Can't Post

I've created a blog using the Instant Realty CMS. Each entry is assigned one or more categories using a multiple checkbox field called "category". I want to create a couple of pages that display records in the blog table, filtered by specified category. Here is the load records code I'm using:

<?php
require_once "/home/content/h/o/c/hockadayhunter/html/brafford/cmsAdmin/lib/viewer_functions.php";

list($blogRecords, $blogMetaData) = getRecords(array(
'tableName' => 'blog',
'perPage' => '10',
'where' => 'Where category="Financing"',
));

I get a mySQL syntax error. I've also tried putting asterisks on either side of "Financing" and that didn't work. Thanks in advance for your help!


Chris
Staff


Oct 19, 2009, 12:06 PM

Post #2 of 5 (4224 views)
Shortcut
Re: [nprivette] Filter Using a Checkbox Field [In reply to] Can't Post

Hi nprivette,

Try this line of code:


Code
'where' => "category LIKE '%\tFinancing\t%'",


Basically, multi-value list fields (such as multiple checkbox fields) contain a tab-separated list of values, with an extra tab on both ends to make it easy to search for a term as above. The SQL above looks for anything (%), followed by a tab (\t), followed by Financing, followed by another tab (\t), followed by anything (%).

I hope this helps! Please let me know if you have any questions.
Chris


nprivette
User

Oct 20, 2009, 2:40 PM

Post #3 of 5 (4184 views)
Shortcut
Re: [chris] Filter Using a Checkbox Field [In reply to] Can't Post

Like a charm. Thanks!


nprivette
User

Oct 21, 2009, 8:29 PM

Post #4 of 5 (4120 views)
Shortcut
Re: [nprivette] Filter Using a Checkbox Field [In reply to] Can't Post

Hi Chris, thanks for your help with this question. I have another somewhat related question:

I have set up a page that lists article titles. Clicking on the name of the article links to a page called articledetail.asp and passes the article number as a parameter. Like so:

http://www.braffordconstruction.com/ArticleDetail.php?id=1

How can I modify the where statement so it uses the variable "id" as the criterion? I tried this

'where' => "category LIKE '($_GET['id'])'",

but get a parse error.

Thanks!


nprivette
User

Oct 21, 2009, 9:04 PM

Post #5 of 5 (4119 views)
Shortcut
Re: [nprivette] Filter Using a Checkbox Field [In reply to] Can't Post

Never mind, I figured out how to do it.