Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function getItems($db=null,$limit=20,$page='',$where='') {
- // check if $db exists before doing anything
- if ($db) {
- $sql1 = $db->prepare("SELECT * FROM classified ORDER BY date DESC");
- /*** fetch Number of results ***/
- $total_pages =$sql1->rowCount();
- $stages = 3;
- if($page){
- $start = ($page - 1) * $limit;
- }else{
- $start = 0;
- }
- $sql = $db->prepare("SELECT * FROM classified $where ORDER BY date DESC LIMIT $start,
- $limit ")or die(print_r($sql->errorInfo(), true));
- $sql->execute();
- $result = $sql->fetchAll();
- } else {
- // I return an empty array here so that if something should fail $result will still be populated with an array
- return array();
- }
- return $result;
- }
- $targetpage = "index.php";
- $result = getItems($db,20,$_GET['page'],'where type = "1"');
- //Include pagination
- require_once("pagination.php");
- // pagination
- echo $paginate;
- foreach($result as $row){
- $id = htmlentities($row['id'], ENT_QUOTES);
- $id_city = htmlentities($row['id_city'], ENT_QUOTES);
- $title = htmlentities($row['title'], ENT_QUOTES ,'utf-8');
- $querya = $db->prepare("SELECT * FROM city WHERE id = :id_city");
- /*** bind the paramaters ***/
- $querya->bindParam(':id_city', $id_city, PDO::PARAM_INT);
- /*** execute the prepared statement ***/
- $querya->execute();
- /*** fetch the results ***/
- $resultya = $querya->fetchAll();
- foreach ($resultya as $rowa) {
- $city_name = htmlentities($rowa['city'], ENT_QUOTES, 'utf-8');
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement