I think that using a loop to contruct the WHERE clause is causing me too much trouble, I really need to get this done today and I can see that my boss is going to start riding me soon. (lets not go there though! 🙂)
I currently have something like this going on, only problems are : empty fields, and I need to make it check for price range to and from, and if those values are empty and yadda yadda, getting hard, anyone have ideas I might be able to borrow? 🙂
thanks for the help up until now also, you've all been awesome!
$fields=array('make', 'model', 'calibre', 'action_type');
for($i=0; $i< count($fields); $i++) {
if(!empty($_POST[$fields[$i]])){
$where.=($where==''?'':' && ').$fields[$i]." LIKE '%".$_POST[$fields[$i]]."%'";
}
}
$where .= " && rrp => '$prc_rng_from' && rrp =< '$prc_rng_to'";
include("docs/include.php");
$query = "SELECT DISTINCT make, model, calibre, action_type, rrp FROM stock WHERE $where";
print "<b>QUERY: </b>".$query."<br />\n\r<br />\n\r";
print "<b>WHERE: </b>$where<br />\n\r<br />\n\r";
$result = MYSQL_QUERY($query, $conn);
if(!$result){
die(MYSQL_ERROR());
}
edit: edited code, went back to using the loop for the regular fields, can apply other things like less or more for price range later... right? eep