Advertisement
Guest User

Looping through values in POST/GET

a guest
Apr 13th, 2013
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.54 KB | None | 0 0
  1. $criteria = array('ctitle', 'csubject', 'creference', 'cat_id', 'cmaterial', 'ctechnic', 'cartist', 'csource', 'stolen');
  2. $likes = "";
  3. foreach ( $criteria AS $criterion ) {
  4.     if ( ! empty($_POST[$criterion]) ) {
  5.         $value = mysql_real_escape_string($_POST[$criterion]);
  6.         $likes .= " AND `$criterion` = '%$value%'";
  7.     } elseif ( ! empty($_GET[$criterion]) ) {
  8.         $value = mysql_real_escape_string($_GET[$criterion]);
  9.         $likes .= " AND `$criterion` = '%$value%'";
  10.     }
  11. }
  12. $query = "SELECT * FROM collections WHERE c_id>0" . $likes . " ORDER BY c_id ASC";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement