嗨即時嘗試讓這個特定的代碼工作的類別頁面。不知道如何安排它。PHP,類別,從INNERJOIN選擇在哪裏
$cat = $_GET['cat'];
}
$record_count = $db->query("SELECT * FROM posts WHERE category_id='$cat'");
$per_page = 3;
$pages = ceil($record_count->num_rows/$per_page);
echo $cat;
if (isset($_GET['p']) && is_numeric($_GET['p'])){
$page = $_GET['p'];
}else{
$page = 1;
}
if($page<=0)
$start=0;
else
$start = $page * $per_page - $per_page;
$prev = $page - 1;
$next = $page + 1;
$query = $db->prepare("SELECT post_id, title, date, image, LEFT(body, 150) AS body, category FROM posts WHERE posts.category_id=$cat INNER JOIN categories ON categories.category_id=posts.category_id order by post_id desc limit $start, $per_page");
$query->execute();
$query->bind_result($post_id, $title, $date, $image, $body, $category);
這包括pagnation,特別是看這條線。但以分離需要的是似乎越硬CATEGORY_ID(至少對我來說)使用兩個MySQL表
帖比預期
$query = $db->prepare("SELECT post_id, title, date, image, LEFT(body, 150) AS body, category FROM posts WHERE posts.category_id=$cat INNER JOIN categories ON categories.category_id=posts.category_id order by post_id desc limit $start, $per_page");
:POST_ID標題日期圖像身體鏈路鏈接名稱CATEGORY_ID
類別:類別CATEGORY_ID
它更好地在這裏添加模式,所以我們可以看到表結構。 – Shawn