確定SI我不是很fimiliar與PDO我只是出發,可能有人幫助我在這裏,爲什麼我的成績將不顯示?頁面是工作,但沒有數據將顯示..將我的舊腳本轉換爲PDO結果不顯示?
<?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> ';
}
}
}
?>
將非常感謝您的時間和幫助
務必檢查錯誤。不要以爲你的查詢是成功的。 –
是的,我有固定的,但還沒有數據顯示 – Seeker
順便說,'$ result'沒有定義,但你檢查說變量,如果它是一個的ressource。 '$ res'將包含任何行。 –