Selecting individual items from multi item list box

4 posts by 2 authors in: Forums > CMS Builder
Last Post: October 6, 2008   (RSS)

By MisterJim - October 4, 2008

I've created a multi-list drop down box for one of my tables within a certain section. It's for a product section that I've created. The idea is that by selecting various items in the box, the code will know to display that item throughout various parts of the site where specific types of product are displayed: i.e., Sale, Rent, etc. This way you can have one table for products and then, depending upon which items are selected, the items may appear in one or more areas throughout the site.

My question is this...

Now that I've got the multi-item drop box created and working, what is the php or mysql code that needs to be used to check for the existance of one or more of the items within the various products so that only those records will be selected? I guess I need something like (X list CONTAINS "xxxxx" OR "yyyyy" OR "zzzzz"). You get the idea.

Also, Dave... I noticed that when I create the items for the multi-list box, they are dropped into the actual mysql with both leading and trailing spaces. This makes it so that if you do a simple query for something that equals something else, the record does not show up. I've had to manually go into the table and remove the extra spaces.

Jim
WebCamp One, LLC



Websites That Work

Re: [Mr Jim] Selecting individual items from multi item list box

By MisterJim - October 6, 2008

For anyone who's interested, I found that there's a very easy way to do what it is I was trying to do.

Simply needed to use the LIKE command in the SQL statment that is used to populate the array.

In my case, where I'm looking for items that are for Sale, it was as simple as adding:

'where' => "display_areas LIKE '%Sale%'",

Jim
WebCamp One, LLC



Websites That Work

Re: [Mr Jim] Selecting individual items from multi item list box

By Dave - October 6, 2008

Hi Jim,

Multi value fields are stored in the database as tab separated values with a leading and trailing tab. This is so you can search for (tab)your value(tab) and always get an exact match. In mysql that's:

'where' => "display_areas LIKE '%\tSale\t%'",

You can also try url searches like this:

viewer.php?display_areas=Sale

Hope that helps!
Dave Edis - Senior Developer
interactivetools.com