Advertisement
Guest User

Untitled

a guest
Dec 30th, 2012
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. $input = $_POST['input'];
  2. $categories = $_POST['category'];
  3. $state = $_POST['state'];
  4. $zipcode = $_POST['zipcode'];
  5.  
  6. $qq = $db->prepare(" SELECT * FROM classified ")or die(print_r($qq->errorInfo(),
  7. true));
  8. /*** execute the prepared statement ***/
  9. $qq->execute();
  10.  
  11. /*** echo number of columns ***/
  12. $rows = $qq->fetch(PDO::FETCH_NUM);
  13. if ($rows>0){
  14.  
  15. $query = " SELECT * FROM classified where confirm='0' ";
  16. if(!empty( $_POST['input'])) {
  17.  
  18. $query .= "AND title LIKE '%".$input."%' ";
  19. }
  20.  
  21.  
  22. if (!empty($_POST['category']) )
  23. {
  24. $query .= "AND id_cat = ".$categories." ";
  25.  
  26. }
  27.  
  28. if (!empty($_POST['state']) )
  29. {
  30. $query .= "AND id_state = ".$state." ";
  31.  
  32. }
  33.  
  34.  
  35. if(!empty($_POST['zipcode'])) {
  36.  
  37. $query .= "AND zipcode = ".$zipcode." ";
  38. }
  39. $query .= "ORDER BY date ";
  40.  
  41. }
  42.  
  43. $stmt = $db->prepare($query);
  44. $stmt->execute($params);
  45. $result = $stmt->fetchAll();
  46. // $ro = $stmt->fetch(PDO::FETCH_NUM);
  47.  
  48. // it didn't work when I tried to count rows
  49. if ($result > 0) {
  50. foreach ($result as $row)
  51. {
  52. echo $row['title'];
  53. echo $row['categories'];
  54. echo $row['state'];
  55. echo $row['zipcode'];
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement