Jump to content

lovephp

Members
  • Posts

    530
  • Joined

  • Last visited

Everything posted by lovephp

  1. typos in title i mean phpfreaks
  2. was wondering how many years its been online?
  3. oh god my mistake i should have made this $results= $sth->fetchall(PDO::FETCH_ASSOC); not $rows = $sth->fetchall(PDO::FETCH_ASSOC); now fixed
  4. i also tried BindParam but same no records gets fetched
  5. ok this time serious not guessing i have got rest of it working but running into something which i guess you guys will know better than me for sure i am getting results if i query it like $results = $db->query('SELECT * FROM blog_posts WHERE catID = '.$cat.' ORDER BY postID DESC LIMIT '.$row.','.$records_per_page.'')->fetchAll(); but when i use $cat = $_POST['catid']; $row = $_POST['row']; global $records_per_page; $sth = $db->prepare("SELECT * from blog_posts WHERE catID = ? ORDER BY postID ASC LIMIT ?,?"); $sth->execute(array($cat,$row,$rowperpage)); $sth->execute(); $rows = $sth->fetchall(PDO::FETCH_ASSOC); even with Bind like $sth = $db->prepare("SELECT * from blog_posts WHERE catID = :catID ORDER BY postID ASC LIMIT :row, :records_per_page"); $sth->bindParam(':catID', $cat, PDO::PARAM_INT); $sth->bindParam(':row', $row, PDO::PARAM_INT); $sth->bindParam(':records_per_page', $records_per_page, PDO::PARAM_INT); $sth->execute(); all i get is blank or 0 value but why $results = $db->query('SELECT * FROM blog_posts WHERE catID = '.$cat.' ORDER BY postID DESC LIMIT '.$row.','.$records_per_page.'')->fetchAll(); fetches records without issue?
  6. i did this $query = "SELECT count(id) AS allcount FROM posts WHERE cat :cat"; $stmt->bindParam(':cat', $catid, PDO::PARAM_INT); $stmt->execute(); $allcount = $db->query($query)->fetchColumn(); $qry = "SELECT * FROM posts WHERE cat :cat ORDER BY id ASC LIMIT LIMIT :rowperpage OFFSET :offset"; $stm = $db->prepare($qry); $stm->bindParam(':cat', $catid, PDO::PARAM_INT); $stm->bindParam(':rowperpage', $rowperpage, PDO::PARAM_INT); $stm->bindParam(':offset', $offset, PDO::PARAM_INT); $stm->execute(); $results = $stm->fetchall(PDO::FETCH_ASSOC); and i get error Fatal error: Call to a member function bindParam() on a non-object
  7. i get it like this LIMIT :rowperpage OFFSET :offset ?
  8. hehehe guess-what-my-problem-is game i get u soi do bind to all but offset and perpage limit how am i to bind them? $query = "SELECT count(id) AS allcount FROM posts WHERE cat = :cat"; $stmt->bindParam(':catUrl', $url, PDO::PARAM_INT); $stmt->execute(); $allcount = $db->query($query)->fetchColumn(); $qry = "SELECT * FROM posts WHERE cat = :cat ORDER BY id ASC LIMIT ?,? "; $stm = $db->prepare($qry); $stm->execute(array($offset,$rowperpage)); $results = $stm->fetchall(PDO::FETCH_ASSOC);
  9. whatis is the procedure to add the where clause to this query? i need to display where catid = 1; $catid = 1; $rowperpage = 3; $offset = 0; $query = "SELECT count(id) AS allcount FROM posts"; $allcount = $db->query($query)->fetchColumn(); $qry = "SELECT * FROM posts ORDER BY id ASC LIMIT ?,? "; $stm = $db->prepare($qry); $stm->execute(array($offset,$rowperpage)); $results = $stm->fetchall(PDO::FETCH_ASSOC); do i have to add $catid = 1; $rowperpage = 3; $offset = 0; $query = "SELECT count(id) AS allcount FROM posts WHERE cat = :cat"; $stmt->bindParam(':cat', $catid, PDO::PARAM_STR); $allcount = $db->query($query)->fetchColumn(); $qry = "SELECT * FROM posts WHERE cat = :cat ORDER BY id ASC LIMIT ?,? "; $stm = $db->prepare($qry); $stm->execute(array($offset,$rowperpage)); $results = $stm->fetchall(PDO::FETCH_ASSOC); please guide
  10. It is creating <a href="http://localhost//blogg/category/X/page/N"> but the yes if click it redricts to index.php
  11. this is how it looks now but still not working $pagination = ""; if($last_page > 1){ $pagination .= "<div class='pagination'>"; if($page > 1) $pagination.= "<a href='$pageName/page/1'>« First</a>"; else $pagination.= "<span class='disabled'>« First</span>"; if ($page > 1) $pagination.= "<a href='$pageName/page/".$prev."'>« Previous </a>"; else $pagination.= "<span class='disabled'>« Previous </span>"; if ($last_page < 7 + ($adjacents * 2)) { for ($counter = 1; $counter <= $last_page; $counter++) { if ($counter == $page) $pagination.= "<span class='current'>$counter</span>"; else $pagination.= "<a href='$pageName/page/".$counter."'>".$counter."</a>"; } } elseif($last_page > 5 + ($adjacents * 2)) { if($page < 1 + ($adjacents * 2)) { for($counter = 1; $counter < 4 + ($adjacents * 2); $counter++) { if($counter == $page) $pagination.= "<span class='current'>$counter</span>"; else $pagination.= "<a href='$pageName/page/".$counter."'>".$counter."</a>"; } $pagination.= "..."; $pagination.= "<a href='$pageName/page/'".$second_last."'>".$second_last."</a>"; $pagination.= "<a href='$pageName/page/".$last_page."'>".$last_page."</a>"; } elseif($last_page - ($adjacents * 2) > $page && $page > ($adjacents * 2)) { $pagination.= "<a href='$pageName/page/1'>1</a>"; $pagination.= "<a href='$pageName/page/2'>2</a>"; $pagination.= "..."; for($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++) { if($counter == $page) $pagination.= "<span class='current'>$counter</span>"; else $pagination.= "<a href='$pageName/page/".$counter."'>".$counter."</a>"; } $pagination.= ".."; $pagination.= "<a href='$pageName/page/".$second_last."'>".$second_last."</a>"; $pagination.= "<a href='$pageName/page/".$last_page."'>".$last_page."</a>"; } else { $pagination.= "<a href='$pageName/page/1'>1</a>"; $pagination.= "<a href='$pageName/page/2'>2</a>"; $pagination.= ".."; for($counter = $last_page - (2 + ($adjacents * 2)); $counter <= $last_page; $counter++) { if($counter == $page) $pagination.= "<span class='current'>$counter</span>"; else $pagination.= "<a href='$pageName/page/".$counter."'>".$counter."</a>"; } } } if($page < $counter - 1) $pagination.= "<a href='$pageName/page/".$next."'>Next »</a>"; else $pagination.= "<span class='disabled'>Next »</span>"; if($page < $last_page) $pagination.= "<a href='$pageName/page/".$last_page."'>Last »</a>"; else $pagination.= "<span class='disabled'>Last »</span>"; $pagination.= "</div>"; }
  12. i even edited my pagination urls like $pagination.= "<a href='$pageName/page/".$counter."'>".$counter."</a>"; still does not work
  13. how do i edit now any examples? do i have to modify everything even in db the slog etc?
  14. so my way of pagination modification these codes are ok? $sqlQuery = $db->query("SELECT * FROM blog_posts WHERE catID = '".$catid."' ORDER BY postID DESC"); $count = $sqlQuery->rowCount(); $pageName = $url; //catName $adjacents = 1; global $records_per_page; $page = (int) (isset($_GET['page']) ? $_GET['page'] : 1); $page = ($page == 0 ? 1 : $page); $start = ($page-1) * $records_per_page; $next = $page + 1; $prev = $page - 1; $last_page = ceil($count/$records_per_page); $second_last = $last_page - 1; $pagination = ""; if($last_page > 1){ $pagination .= "<div class='pagination'>"; if($page > 1) echo $pagination.= "<a href='$pageName/page=1'>« First</a>"; else $pagination.= "<span class='disabled'>« First</span>"; if ($page > 1) $pagination.= "<a href='$pageName/page=".$prev."'>« Previous </a>"; else $pagination.= "<span class='disabled'>« Previous </span>"; if ($last_page < 7 + ($adjacents * 2)) { for ($counter = 1; $counter <= $last_page; $counter++) { if ($counter == $page) $pagination.= "<span class='current'>$counter</span>"; else $pagination.= "<a href='$pageName/page=".$counter."'>".$counter."</a>"; } } elseif($last_page > 5 + ($adjacents * 2)) { if($page < 1 + ($adjacents * 2)) { for($counter = 1; $counter < 4 + ($adjacents * 2); $counter++) { if($counter == $page) $pagination.= "<span class='current'>$counter</span>"; else $pagination.= "<a href='$pageName/page=".$counter."'>".$counter."</a>"; } $pagination.= "..."; $pagination.= "<a href='$pageName/page='".$second_last."'>".$second_last."</a>"; $pagination.= "<a href='$pageName/page=".$last_page."'>".$last_page."</a>"; } elseif($last_page - ($adjacents * 2) > $page && $page > ($adjacents * 2)) { $pagination.= "<a href='$pageName/page=1'>1</a>"; $pagination.= "<a href='$pageName/page=2'>2</a>"; $pagination.= "..."; for($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++) { if($counter == $page) $pagination.= "<span class='current'>$counter</span>"; else $pagination.= "<a href='$pageName/page=".$counter."'>".$counter."</a>"; } $pagination.= ".."; $pagination.= "<a href='$pageName/page=".$second_last."'>".$second_last."</a>"; $pagination.= "<a href='$pageName/page=".$last_page."'>".$last_page."</a>"; } else { $pagination.= "<a href='$pageName/page=1'>1</a>"; $pagination.= "<a href='$pageName/page=2'>2</a>"; $pagination.= ".."; for($counter = $last_page - (2 + ($adjacents * 2)); $counter <= $last_page; $counter++) { if($counter == $page) $pagination.= "<span class='current'>$counter</span>"; else $pagination.= "<a href='$pageName/page=".$counter."'>".$counter."</a>"; } } } if($page < $counter - 1) $pagination.= "<a href='$pageName/page=".$next."'>Next »</a>"; else $pagination.= "<span class='disabled'>Next »</span>"; if($page < $last_page) $pagination.= "<a href='$pageName/page=".$last_page."'>Last »</a>"; else $pagination.= "<span class='disabled'>Last »</span>"; $pagination.= "</div>"; }
  15. i have already got my category into seo url like site.com/category-name now i have issue with the pagination i tried but its not taking any affect could one tell me what i am doing wrong? my categories.php <?php require('includes/config.php'); $url = $_SERVER['REQUEST_URI']; $url = str_replace('/blog/category/', '', $url); echo $catid = getCatID($url); $stmt = $db->prepare("SELECT * FROM blog_categories WHERE catUrl = :catUrl"); $stmt->bindParam(':catUrl', $url, PDO::PARAM_STR); $stmt->execute(); $row = $stmt->fetch(); //if post does not exists redirect user. if($row['catUrl'] == ''){ header('Location: ../'); exit; } ?> <!DOCTYPE html> <html> <head> <title><?php echo $row['catName']; ?></title> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="<?php echo DIR; ?>assets/css/bootstrap.min.css"> <link rel="stylesheet" href="<?php echo DIR; ?>assets/css/font-awesome.min.css"> <link rel="stylesheet" href="<?php echo DIR; ?>assets/css/font.css"> <link rel="stylesheet" href="<?php echo DIR; ?>assets/css/animate.css"> <link rel="stylesheet" href="<?php echo DIR; ?>assets/css/structure.css"> <!--[if lt IE 9]> <script src="assets/js/html5shiv.min.js"></script> <script src="assets/js/respond.min.js"></script> <![endif]--> <script src="<?php echo DIR; ?>assets/js/jquery-1.11.1.min.js"></script> <?php include("head_include.php"); ?> </head> <body> <div id="fb-root"></div> <script>(function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/en_GB/sdk.js#xfbml=1&version=v2.10"; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk'));</script> <div id="preloader"> <div id="status"> </div> </div> <a class="scrollToTop" href="#"><i class="fa fa-angle-up"></i></a> <?php include("header.php"); ?> <section id="contentbody"> <div class="container"> <?php $sqlQuery = $db->query("SELECT * FROM blog_posts WHERE catID = '".$catid."' ORDER BY postID DESC"); $count = $sqlQuery->rowCount(); $pageName = $url; //catName $adjacents = 1; global $records_per_page; $page = (int) (isset($_GET['page']) ? $_GET['page'] : 1); $page = ($page == 0 ? 1 : $page); $start = ($page-1) * $records_per_page; $next = $page + 1; $prev = $page - 1; $last_page = ceil($count/$records_per_page); $second_last = $last_page - 1; $pagination = ""; if($last_page > 1){ $pagination .= "<div class='pagination'>"; if($page > 1) echo $pagination.= "<a href='$pageName/page=1'>« First</a>"; else $pagination.= "<span class='disabled'>« First</span>"; if ($page > 1) $pagination.= "<a href='$pageName/page=".$prev."'>« Previous </a>"; else $pagination.= "<span class='disabled'>« Previous </span>"; if ($last_page < 7 + ($adjacents * 2)) { for ($counter = 1; $counter <= $last_page; $counter++) { if ($counter == $page) $pagination.= "<span class='current'>$counter</span>"; else $pagination.= "<a href='$pageName/page=".$counter."'>".$counter."</a>"; } } elseif($last_page > 5 + ($adjacents * 2)) { if($page < 1 + ($adjacents * 2)) { for($counter = 1; $counter < 4 + ($adjacents * 2); $counter++) { if($counter == $page) $pagination.= "<span class='current'>$counter</span>"; else $pagination.= "<a href='$pageName/page=".$counter."'>".$counter."</a>"; } $pagination.= "..."; $pagination.= "<a href='$pageName/page='".$second_last."'>".$second_last."</a>"; $pagination.= "<a href='$pageName/page=".$last_page."'>".$last_page."</a>"; } elseif($last_page - ($adjacents * 2) > $page && $page > ($adjacents * 2)) { $pagination.= "<a href='$pageName/page=1'>1</a>"; $pagination.= "<a href='$pageName/page=2'>2</a>"; $pagination.= "..."; for($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++) { if($counter == $page) $pagination.= "<span class='current'>$counter</span>"; else $pagination.= "<a href='$pageName/page=".$counter."'>".$counter."</a>"; } $pagination.= ".."; $pagination.= "<a href='$pageName/page=".$second_last."'>".$second_last."</a>"; $pagination.= "<a href='$pageName/page=".$last_page."'>".$last_page."</a>"; } else { $pagination.= "<a href='$pageName/page=1'>1</a>"; $pagination.= "<a href='$pageName/page=2'>2</a>"; $pagination.= ".."; for($counter = $last_page - (2 + ($adjacents * 2)); $counter <= $last_page; $counter++) { if($counter == $page) $pagination.= "<span class='current'>$counter</span>"; else $pagination.= "<a href='$pageName/page=".$counter."'>".$counter."</a>"; } } } if($page < $counter - 1) $pagination.= "<a href='$pageName/page=".$next."'>Next »</a>"; else $pagination.= "<span class='disabled'>Next »</span>"; if($page < $last_page) $pagination.= "<a href='$pageName/page=".$last_page."'>Last »</a>"; else $pagination.= "<span class='disabled'>Last »</span>"; $pagination.= "</div>"; } $records = $db->query("SELECT * FROM blog_posts WHERE catID = '".$catid."' ORDER BY postID DESC LIMIT $start, $records_per_page"); $count = $records->rowCount(); if($count == ''){ header('Location: index.php?page=1'); exit; } try { echo '<div class="row">'; echo '<div class=" col-sm-12 col-md-6 col-lg-6">'; echo '<div class="row">'; echo ' <div class="leftbar_content">'; echo ' <h2>'.strtoupper($url).'</h2>'; //$stm = $db->query('SELECT * FROM blog_posts WHERE catID = "'.$catid.'" ORDER BY postID DESC'); //$stm->execute(); while($rw = $records->fetch()){ $img = $rw['postImg']; if(!empty($img)){ $img ="<img src='".DIR."uploads/images/".$img."' alt=''"; }else{ $img = ""; } $youtube = $rw['postYoutube']; if(!empty($youtube)){ $youtube ='<div class="videoholder"> <iframe width="720" height="450" src="//www.youtube.com/embed/'.$youtube.'?autohide=1&fs=1&autoplay=0&iv_load_policy=3&rel=0&modestbranding=1&showinfo=0&controls=1&hd=1" frameborder="0" allowfullscreen=""></iframe></div>'; }else{ $youtube = ""; } echo ' <div class="single_stuff wow fadeInDown">'; echo '<div class="single_stuff_img"> <a href="'.DIR.'post/'.$rw['postSlug'].'">'.$img.$youtube.'</a> </div>'; echo '<div class="single_stuff_article">'; echo '<div class="single_sarticle_inner"> <a class="stuff_category" href="#">Technology</a>'; echo '<div class="stuff_article_inner"> <span class="stuff_date">'.date('jS M Y', strtotime($row['postDate'])).'</span>'; echo '<h2><a href="'.DIR.'post/'.$rw['postSlug'].'">'.$rw['postTitle'].'</a></h2>'; echo ' <p>'.$rw['postDesc'].'</p>'; echo '</div>'; echo '</div>'; echo '</div>'; echo '</div>'; } } catch(PDOException $e) { echo $e->getMessage(); } ?> <div class="stuffpost_paginatinonarea wow slideInLeft"> <ul class="newstuff_pagnav"> <li><?php echo $pagination; ?></li> </ul> </div> </div> </div> </div> <?php include("sidebar.php"); ?> <?php include("footer.php"); ?> <script src="<?php echo DIR; ?>assets/js/jquery.min.js"></script> <script src="<?php echo DIR; ?>assets/js/bootstrap.min.js"></script> <script src="<?php echo DIR; ?>assets/js/wow.min.js"></script> <script src="<?php echo DIR; ?>assets/js/custom.js"></script> </body> </html> and here is my htaccess Options +FollowSymLinks RewriteEngine On RewriteBase /blogg/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^post/(.*)\?*$ post.php?$1 [L,QSA] RewriteRule ^category/([a-zA-Z0-9-/]+)/page/(.+)/?$ categories.php?$1&page=$2 [L,QSA] RewriteRule ^category/(.*)\?*$ categories.php?$1 [L] RewriteRule ^tag/(.*)\?*$ tag.php?$1 [L,QSA] the category like localhost/blog/category/eateries i am able to open but when i tried to access page like localhost/blog/category/eateries/page/2 but i get redirected to index.php instead
  16. the manuals are soo long and words used are so hard for me to understand but yes at times i do read
  17. thanks learning more with practice but still a long way to go i guess
  18. you r right mate i need to bind but first i need to know what is wrong in my conversion im sure its definitely wrong thats why no records display
  19. problem solved mate used another means to achieve it
  20. i got the following mysql functions which i need to convert into pdo but yes still not expert in pdo so need guidance what i am doing wrong in my conversion the original <?php $rowperpage = 3; // counting total number of posts $allcount_query = "SELECT count(*) as allcount FROM posts"; $allcount_result = mysql_query($allcount_query); $allcount_fetch = mysql_fetch_array($allcount_result); $allcount = $allcount_fetch['allcount']; // select first 3 posts $query = "select * from posts order by id asc limit 0,$rowperpage "; $result = mysql_query($query); while($row = mysql_fetch_array($result)){ $id = $row['id']; $title = $row['title']; $content = $row['content']; $shortcontent = substr($content, 0, 160)."..."; $link = $row['link']; ?> <!-- Post --> <div class="post" id="post_<?php echo $id; ?>"> <h1><?php echo $title; ?></h1> <p> <?php echo $shortcontent; ?> </p> <a href="<?php echo $link; ?>" class="more" target="_blank">More</a> </div> <?php } ?> what i am trying $query = "SELECT count(*) FROM posts"; $stmt = $db->prepare($query); $allcount_fetch = $stmt->fetch(PDO::FETCH_ASSOC); $allcount = $stmt->fetchColumn(); $qry = "select * from posts order by id asc limit 0,$rowperpage "; $stm = $db->prepare($qry); while($row = $stm->fetch(PDO::FETCH_ASSOC)){ $id = $row['id']; $title = $row['title']; $content = $row['content']; $shortcontent = substr($content, 0, 160)."..."; $link = $row['link']; ?> <!-- Post --> <div class="post" id="post_<?php echo $id; ?>"> <h1><?php echo $title; ?></h1> <p> <?php echo $shortcontent; ?> </p> <a href="<?php echo $link; ?>" class="more" target="_blank">More</a> </div> <?php } ?> but i get a blank page instead
  21. but then in edit form i will again have to fetch records of tags table and postTags table matching the blog post how can i do that to loop inside one another? By no means can the way i did is achievable?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.