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:

  1. define class
  2. make rules
  3. get query
  4. 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

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -