Forum Moderators: coopster

Message Too Old, No Replies

checking array value against serialized column data

         

bkeep

2:29 am on Mar 6, 2008 (gmt 0)

10+ Year Member



Some background here is I am building a classifieds ad system. lets say you installed this script and as a new site owner you go through the process of setting up your site options (I have set this up so the site admin can add/edit their own features). you go to the add features page and add a couple of features for your cars you would like to sell, say like Anti-Lock Brakes, Tinted Windows etc... This creates a table features with columns id, features.

Now that you have added a couple of listing you want the users to be able to search by the features so if only 2 out of 5 listings are equipped with Anti-Lock brakes it will only pull up those 2 listings.

I have scratched my head over this one. I am only using one item to ease readability. I hope it works.

I have a database column that contains a serialized dataset

serialize($_POST["features"]) the features id is entered from addlisting.php. It is pulled out in a select list with the name = id
a:1:{i:0;s:2:"16";}

I then have a search page which has a multi field select box that passes an array to the script

features[] this posts to listings.php
Array ( [0] => 16 )

this then builds a querystring

if (!empty($_POST["make"])) {
if (!empty($addOnSQL))
$addOnSQL.=" AND ";
$addOnSQL.="make = '" . $_POST["make"] . "'";
}

if (!empty($_POST["features"])) {
if (!empty($addOnSQL))
$addOnSQL.=" AND ";
$addOnSQL.="features = '" . $_POST["features"] . "'";
}

so this is my query
$sql = "SELECT * FROM listings WHERE $addOnSQL";

Is there a way to check if the passed value exists in the serialized dataset? basically does item 16 exist in the column with the serialized dataset? if it doesn't skip pulling this record if it does pull the record and add it to the recordset.

Keep in mind there may be up to 10 or so items being searched on

Thanks for any help
Best Regards,
Brandon

coopster

9:20 pm on Mar 18, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I'm not entirely certain I quite understand what you are asking here, but would regular expression matching work?