PHP MYSQL - Filter and sort function -
i m working on filter , sort option website , seem stuck. whole code can seen here: http://pastebin.com/pyfnlisz
it's not 100% complete ... parts this
if(array_key_exists('number', $sorts)) { $issue = $sorts['number']; $setissue = "and i.item_number = ?"; }
still need edited bit, hope it's understandable.
the part can't figure out this(line 126 in pastebin):
if( !empty($userids) && $letter ) { $ref = array(); foreach($userids $id) { $ref[] = $id['followed']; } $ref[] = $letter; $params = implode(",", array_fill(0, count($userids), "?"))."?"; $prep = implode("", array_fill(0, count($userids), "i"))."s"; }
i'm not sure how make above if
dynamic. need if $userids
array not empty , either $letter
or $year
or $publisher
or $number
set. can combination. items belonging users in $userids
array , filtered letter, year, publisher, number , maybe in future other filters. or can year , publisher, or publisher, number , year ... , on.
since trying "combination of constraints or conditions", can suggest below pattern i've used shops:
- define class
- make rules
- get query
optimize cache or other things
class condition { public function add($query) { $this->query[] = $query; return $this; } public function get() { return " select * table " . implode(" , " ,$this->query); } $con = new condition(); $query = $con->add("price > 100 , price < 200")->add("year > 1980")->get();
Comments
Post a Comment