Php 如何从数据库中获取活动帖子
这是我的索引页代码。我已经使用了where子句,但是抛出了一些错误Php 如何从数据库中获取活动帖子,php,sql,Php,Sql,这是我的索引页代码。我已经使用了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.Subcateg
$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表如下所示:
我没有真正理解你真正的要求,但基于你的问题 您可以在sql中添加“where”条件
例如:
选择。。。。来自tbl_name,其中tbl_name.status!='0';代码>我认为您在SQL查询方面遇到了问题,因为您的问题可能与从数据库获取数据有关。根据您提供的表的查询和屏幕截图,以下代码将从is\u 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");
在上面的代码中,tblposts.is_active=0
将过滤中值为0的帖子。请澄清您的问题。您可以在请求中添加一个简单的WHEREWHERE status!=0
如果您只打算使用列名访问结果集数据,请只创建一个关联结果集。是否可以添加您得到的错误?表结构也可用于获取此类错误警告:mysqli_fetch_array()期望参数1为mysqli_result,布尔值在第58行的C:\xampp\htdocs\newsportal\index.php中给出