Advertisement
Guest User

Revised loop

a guest
Apr 13th, 2013
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $criteria = array('ctitle', 'csubject', 'creference', 'cat_id', 'cmaterial', 'ctechnic', 'cartist', 'csource', 'stolen');
  2. $likes = "";
  3. $url_criteria = '';
  4. foreach ( $criteria AS $criterion ) {
  5.     if ( ! empty($_POST[$criterion]) ) {
  6.         $value = ($_POST[$criterion]);
  7.         $likes .= " AND `$criterion` = '%$value%'";
  8.         $url_criteria .= '&'.$criterion.'='.htmlentities($_POST[$criterion]);
  9.     } elseif ( ! empty($_GET[$criterion]) ) {
  10.         $value = mysql_real_escape_string($_GET[$criterion]);
  11.         $likes .= " AND `$criterion` = '%$value%'";
  12.         $url_criteria .= '&'.$criterion.'='.htmlentities($_GET[$criterion]);
  13.     }
  14. }
  15. $query = "SELECT * FROM collections WHERE c_id>0" . $likes . " ORDER BY c_id ASC";
  16.  
  17. // then append the $url_criteria onto any of the hrefs you need to create for pagination, e.g.
  18. echo '<a href="myurl.php?page=1'.$url_criteria.'" title="Page 1">Page 1</a>';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement