Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/230.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_Mysqli - Fatal编程技术网

Php 如何在准备好的语句中结合单行和数据数组

Php 如何在准备好的语句中结合单行和数据数组,php,mysqli,Php,Mysqli,我有两张桌子和一张桌子。一个广告帖子行在广告img中有许多图像。我试图同时执行两个查询,然后在最后合并。但是 表:ad\u图像 立柱(img\u id,ad\u id,img\u name) 表:ad\u post 列(id,用户id,标题,价格,cat,condit,说明,vid) 关系 广告贴(1)--->(许多)广告图片 我现在已经有了广告的ID,我想将IMG保存在$ad_set数组中 图像数组的值返回null,有什么问题?空白屏幕?意外输出?猜猜你自己?图像数组值为空如果我理解正确,我相

我有两张桌子和一张桌子。一个广告帖子行在广告img中有许多图像。我试图同时执行两个查询,然后在最后合并。但是 表:
ad\u图像
立柱(
img\u id
ad\u id
img\u name
) 表:
ad\u post
列(
id
用户id
标题
价格
cat
condit
说明
vid
) 关系 广告贴(1)--->(许多)广告图片

我现在已经有了广告的ID,我想将IMG保存在$ad_set数组中
图像数组的值返回null

,有什么问题?空白屏幕?意外输出?猜猜你自己?图像数组值为空如果我理解正确,我相信你需要使用join链接查询你在
stmt1
中查询图像。尝试
while($stmt1->fetch()!=NULL){}
我使用了join,但它提供了重复的数据。。。。我试图从广告文章中获取每一行的id,然后使用该id获取广告文章每一行的图像数组
public function read_ads()
{
    $this;
    $this->sql = 'SELECT ad_post.id,ad_post.user_id,ad_post.title,ad_post.price,
             sub_cat.s_cat_name,ad_post.condit,ad_post.description,ad_post.vid FROM  ad_post,sub_cat 
            where sub_cat.id=ad_post.cat';
    $sql1 = 'SELECT `img_id`,`img_name` FROM `ad_images` WHERE ad_id=?';
    $stmt = $this->con->prepare ( $this->sql );
    $stmt1 = $this->con->prepare ( $sql1 );

    if ($stmt === false) {
        trigger_error ( 'Wrong SQL: ' . $sql . ' Error: ' . $conn->error, E_USER_ERROR );
    }
    // STMT
    $stmt->execute ();
    $stmt->store_result ();
    $stmt->bind_result ( $id, $uId, $title, $price, $cat, $usage, $desc, $vid );
    // STMT1

    // $ad =AdPost::__getAll('','','','','','','','');
    // $ad = Array();
    $img = Array ();
    $count = 0;
    $count = 0;
    $ads_img = Array ();
    $a_img = Array ();
    while ( $stmt->fetch () != NULL ) {

        $stmt1->bind_param ( 'i', $id );
        $stmt1->execute ();
        $stmt1->store_result ();
        $stmt1->bind_result ( $img_id, $img_name );
        while ( $stmt1->fetch () != NULL ) {
            echo $img_id;
            $a_img = Array (
                    'img_id' => $img_id,
                    'img_name' => $img_name 
            );
            try {
                $ads_img [$count] = $a_img;
            } catch ( Exception $exc ) {
                echo $exc->getTraceAsString ();
            }
        }
        $count ++;
        $ad_set = Array (
                'id' => $id,
                'uid' => $uId,
                'title' => $title,
                'price' => $price,
                'cat' => $cat,
                'usage' => $usage,
                'desc' => $desc,
                'img_name' => $a_img
        );
        try {
            $ads [$count] = $ad_set;
        } catch ( Exception $exc ) {
            echo $exc->getTraceAsString ();
        }

        $count ++;
    }

    $stmt->free_result ();
    $stmt->close ();

    return $ads;

}