Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何从数据库中获取活动帖子_Php_Sql - Fatal编程技术网

Php 如何从数据库中获取活动帖子

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

这是我的索引页代码。我已经使用了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表如下所示:


我没有真正理解你真正的要求,但基于你的问题

您可以在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的帖子。

请澄清您的问题。您可以在请求中添加一个简单的WHERE
WHERE status!=0
如果您只打算使用列名访问结果集数据,请只创建一个关联结果集。是否可以添加您得到的错误?表结构也可用于获取此类错误警告:mysqli_fetch_array()期望参数1为mysqli_result,布尔值在第58行的C:\xampp\htdocs\newsportal\index.php中给出