这是我的索引页代码。我已经使用了where子句,但是抛出了一些错误
$query = mysqli_query($con,"SELECT
tblposts.id AS pid,
tblposts.PostTitle AS posttitle,
tblposts.PostImage,
tblcategory.CategoryName AS category,
tblcategory.id AS cid,
tblsubcategory.Subcategory AS subcategory,
tblposts.PostDetails AS postdetails,
tblposts.PostingDate AS postingdate,
tblposts.PostUrl AS url
FROM tblposts
LEFT JOIN tblcategory ON tblcategory.id=tblposts.CategoryId
LEFT JOIN tblsubcategory ON tblsubcategory.SubCategoryId=tblposts.SubCategoryId
ORDER BY tblposts.id DESC LIMIT $offset, $no_of_records_per_page");
我的tblposts表如下:
答案 0 :(得分:1)
我认为您在使用SQL查询时遇到问题,因为您的问题很可能与从数据库中获取数据有关。根据您提供的表格的查询和屏幕截图,以下代码将过滤is_active
列中的帖子。
$query = mysqli_query($con,"SELECT
tblposts.id AS pid,
tblposts.PostTitle AS posttitle,
tblposts.PostImage,
tblcategory.CategoryName AS category,
tblcategory.id AS cid,
tblsubcategory.Subcategory AS subcategory,
tblposts.PostDetails AS postdetails,
tblposts.PostingDate AS postingdate,
tblposts.PostUrl AS url
FROM tblposts
LEFT JOIN tblcategory ON tblcategory.id=tblposts.CategoryId
LEFT JOIN tblsubcategory ON tblsubcategory.SubCategoryId=tblposts.SubCategoryId
WHERE tblposts.is_active = 0
ORDER BY tblposts.id DESC LIMIT $offset, $no_of_records_per_page");
在上面的代码中,WHERE tblposts.is_active = 0
将过滤在is_active
列上的值为0的帖子。
答案 1 :(得分:0)
我并没有真正得到您真正想要的,但是根据您的问题...
您可以在sql上添加“ where”条件。
例如:SELECT .... FROM tbl_name WHERE tbl_name.status != '0';