lovephp Posted March 14, 2016 Share Posted March 14, 2016 can someone tell me why the results are not displaying? <?php require_once 'db/_db.php'; $stmt = $db->prepare("SELECT ^ FROM article"); $stmt->execute(); $result = $stmt->fetchAll(); $total_rows = $stmt->rowCount(); //$allRecords = mysql_query('select * from article'); //$total_rows = mysql_num_rows($allRecords); //$base_url = 'https://localhost/pagi/'; // global $per_page; $num_links = 4; $total_rows = $total_rows; $cur_page = 1; if(isset($_GET['page'])) { $cur_page = $_GET['page']; $cur_page = ($cur_page < 1)? 1 : $cur_page; //if page no. in url is less then 1 or -ve } $offset = ($cur_page-1)*$per_page; //setting offset $pages = ceil($total_rows/$per_page); $start = (($cur_page - $num_links) > 0) ? ($cur_page - ($num_links - 1)) : 1; $end = (($cur_page + $num_links) < $pages) ? ($cur_page + $num_links) : $pages; //$res = mysql_query("SELECT * FROM article ORDER BY id DESC LIMIT ".$per_page." OFFSET ".$offset); $stm = $db->prepare("SELECT * FROM article ORDER BY id DESC LIMIT ".$per_page." OFFSET ".$offset); $stm->execute(); $res = $stm->fetchAll(); $rows = $stm->rowCount(); if($rows < 1){ header("Location: news-events.php"); exit; } if(is_resource($result)) { foreach( $res as $row ) { $desc = $row["ne_article"]; $img = $row['ne_image']; if(!empty($img)){ $img = '<br/><img src="uploads/images/'.$img.'" alt="" class="responsive-shrink">'; }else{ $img = ''; } $youtube = $row["ne_youtube"]; if(!empty($youtube)){ $youtube = '<br/><div class="video-container"><iframe src="http://www.youtube.com/embed/'.$youtube.'"></iframe></div>'; }else{ $youtube = ''; } //shortenString($row['ne_article']); ?> <h4><a href="<?php echo $row['ne_url']; ?>"><?php echo $row['ne_title']; ?></a></h4> <h5><b>Views:</b> <?php echo $row['views']; ?>, <b>Posted on:</b> <?php echo format_date($row['created']); ?></h5> <?php echo $img; ?> <?php echo $youtube; ?> <p> <br/><?php echo bbcode(nl2br(shortenString($desc))); ?> </p> <div id="pagelink"> <a href="<?php echo $row['ne_url']; ?>" class="myButton"> Read more...</button></a> </div> <?php } } ?> <div id="pagination"> <div id="pagiCount"> <br/><br/> <?php if(isset($pages)) { if($pages > 1) { if($cur_page > $num_links) // for taking to page 1 // { $dir = "First"; echo '<span id="prev"> <a href="'.$_SERVER['PHP_SELF'].'?page='.(1).'">'.$dir.'</a> </span>'; } if($cur_page > 1) { $dir = "Prev"; echo '<span id="prev"> <a href="'.$_SERVER['PHP_SELF'].'?page='.($cur_page-1).'">'.$dir.'</a> </span>'; } for($x=$start ; $x<=$end ;$x++) { echo ($x == $cur_page) ? '<strong>'.$x.'</strong> ':'<a href="'.$_SERVER['PHP_SELF'].'?page='.$x.'">'.$x.'</a> '; } if($cur_page < $pages ) { $dir = "Next"; echo '<span id="next"> <a href="'.$_SERVER['PHP_SELF'].'?page='.($cur_page+1).'">'.$dir.'</a> </span>'; } if($cur_page < ($pages-$num_links) ) { $dir = "Last"; echo '<a href="'.$_SERVER['PHP_SELF'].'?page='.$pages.'">'.$dir.'</a> '; } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/301003-converting-my-old-script-to-pdo-results-do-not-show/ Share on other sites More sharing options...
Jacques1 Posted March 14, 2016 Share Posted March 14, 2016 What is SELECT ^ FROM article supposed to do? Quote Link to comment https://forums.phpfreaks.com/topic/301003-converting-my-old-script-to-pdo-results-do-not-show/#findComment-1531997 Share on other sites More sharing options...
lovephp Posted March 14, 2016 Author Share Posted March 14, 2016 What is SELECT ^ FROM article supposed to do? oops sorry corrected it * but still i only get is the paging number not the data, nothing is displaying from article table Quote Link to comment https://forums.phpfreaks.com/topic/301003-converting-my-old-script-to-pdo-results-do-not-show/#findComment-1531999 Share on other sites More sharing options...
Jacques1 Posted March 14, 2016 Share Posted March 14, 2016 There are dozens of potential and actual problems in your code, so you'll have to be a lot more specific. Check your PHP error log. Use var_dump() to analyze the behavior of your program. Where exactly do things go wrong? Your code contains the check if(is_resource($result)) { ... } But $result is an array, and it's completely unrelated to the query at hand. I assume that's a leftover from your old code. 1 Quote Link to comment https://forums.phpfreaks.com/topic/301003-converting-my-old-script-to-pdo-results-do-not-show/#findComment-1532004 Share on other sites More sharing options...
lovephp Posted March 14, 2016 Author Share Posted March 14, 2016 (edited) in error logs i find nothing related to this but yes i found this yes that is_resource($result) is previous code how on earth i deal with the pagination without that? [Tue Mar 15 01:50:40 2016] [error] [client 127.0.0.1] PHP Parse error: parse error in C:\\wamp\\www\\web\\article.php on line 24, referer: http://localhost/web/news-events.php Edited March 14, 2016 by lovephp Quote Link to comment https://forums.phpfreaks.com/topic/301003-converting-my-old-script-to-pdo-results-do-not-show/#findComment-1532006 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.