Advertisement
Guest User

Untitled

a guest
Feb 6th, 2013
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. <?php
  2. function getItems($db=null,$limit=20,$page='',$where='') {
  3. // check if $db exists before doing anything
  4. if ($db) {
  5. $sql1 = $db->prepare("SELECT * FROM classified ORDER BY date DESC");
  6. /*** fetch Number of results ***/
  7. $total_pages =$sql1->rowCount();
  8. $stages = 3;
  9. if($page){
  10. $start = ($page - 1) * $limit;
  11. }else{
  12. $start = 0;
  13. }
  14. $sql = $db->prepare("SELECT * FROM classified $where ORDER BY date DESC LIMIT $start,
  15. $limit ")or die(print_r($sql->errorInfo(), true));
  16. $sql->execute();
  17. $result = $sql->fetchAll();
  18. } else {
  19. // I return an empty array here so that if something should fail $result will still be populated with an array
  20. return array();
  21. }
  22. return $result;
  23. }
  24.  
  25.  
  26. $targetpage = "index.php";
  27.  
  28. $result = getItems($db,20,$_GET['page'],'where type = "1"');
  29.  
  30. //Include pagination
  31. require_once("pagination.php");
  32. // pagination
  33. echo $paginate;
  34.  
  35. foreach($result as $row){
  36. $id = htmlentities($row['id'], ENT_QUOTES);
  37. $id_city = htmlentities($row['id_city'], ENT_QUOTES);
  38. $title = htmlentities($row['title'], ENT_QUOTES ,'utf-8');
  39. $querya = $db->prepare("SELECT * FROM city WHERE id = :id_city");
  40. /*** bind the paramaters ***/
  41. $querya->bindParam(':id_city', $id_city, PDO::PARAM_INT);
  42. /*** execute the prepared statement ***/
  43. $querya->execute();
  44. /*** fetch the results ***/
  45. $resultya = $querya->fetchAll();
  46. foreach ($resultya as $rowa) {
  47. $city_name = htmlentities($rowa['city'], ENT_QUOTES, 'utf-8');
  48. }
  49. }
  50. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement