警告:mysqli_fetch_assoc()期望参数1为mysqli_result,布尔值为

时间:2016-10-17 10:01:04

标签: php mysqli fetch

拥有这段代码:

$query_product=mysqli_query($connect,"SELECT `products`.`product_id` as product_id,
                                if(`products_variants`.`stock`=0,'false','true') as stock,
                                `products`.`url` as url,
                                `products`.`price` as price,
                                `products`.`large_image` as picture,
                                `brands`.`name` as vendor,
                                `products`.`model` as model,
                                `products`.`body` as description,
                                `brands`.`country` as country
                                FROM `products` INNER JOIN `brands` ON `products`.`brand_id` = `brands`.`brand_id` LEFT JOIN `products_variants` ON `products`.`product_id`=`products_variants`.`product_id`
                                WHERE `products`.`enabled`=1 AND `products`.`price`<>0 AND `products`.`category_id` IN (".$subcategories.")
                                 ");

我检查过$query_product,当我在托管服务器上运行此代码时,它是空的。具有相同数据库的相同代码在本地服务器上正常工作。我不会问我是否在类似主题中找到答案。 编辑:更多代码

    <?php
    $dbhost="localhost";                        
    $dbuser="dbuser";                       
    $dbpass="dbpass";                           
    $dbname="dbname";

    $connect=mysqli_connect($dbhost,$dbuser,$dbpass,$dbname);
    //mysql_select_db($dbname,$connect);

    $query_str1="SET NAMES 'utf8'";
    mysqli_query($connect,$query_str1);

    function utf8_replace( $ptr , $replace , $str , $cr = false)
    {
        if(is_array($ptr))
        {
            foreach($ptr as $p)
            {
                $str = utf8_replace($p , $replace , $str , $cr);
            }
            return $str;
        }
        return preg_replace( '/'.preg_quote( $ptr , '/' ).'/su' . ($cr?'i':''), $replace , $str );
    }
    function full_trim($str)
    {
        $b=array('lorem','ipsum','dolor','sit','amet');
        $str=utf8_replace($b, '', $str, true);
        return trim(preg_replace('/\s{2,}/', ' ', $str));
    }
    header("Content-type: text/xml; charset=UTF-8");

    // header of XML
    echo
    "<?xml version='1.0' encoding='UTF-8'?>
    <!DOCTYPE yml_catalog SYSTEM 'shops.dtd'>
    <yml_catalog date='".date('Y-m-d H:m')."'>
    <shop>
    <name>MY SHOP</name>
    <company>MY COMPANY</company>
    <url>http://example.com</url>
    ";
    // Currencies
    echo "<currencies>
    ";
    echo "<currency id='RUR' rate='1'/>
    ";
    echo "<currency id='EUR' rate='CBRF'/>
    ";
    echo "<currency id='USD' rate='CBRF'/>
    ";
    echo "</currencies>
    ";
    // Categories
    echo "<categories>
    ";
    echo  "<category id='1' parentId='0'>Air compressors</category>
    ";
    echo "</categories>
    ";
    // Products  
    echo "<offers>
    ";

    // Categories list
    $bigger_categories="70,214,218,372,116,337,381";

    $query_categories=mysqli_query($connect,"SELECT categories.category_id FROM categories WHERE enabled=1 AND categories.parent IN (".$bigger_categories.")" );
    $row_subcategories = array();
    while($row_categories=mysqli_fetch_assoc($query_categories))
    {
        $row_subcategories[] = $row_categories['category_id'];
    }
    $subcategories = implode(",",$row_subcategories);

    $query_categories=mysqli_query($connect,"SELECT categories.category_id FROM categories WHERE enabled=1 AND categories.parent IN (".$subcategories.")" );
    $row_subcategories = array();
    while($row_categories=mysqli_fetch_assoc($query_categories))
    {
        $row_subcategories[] = $row_categories['category_id'];
    }
    $subcategories2 = implode(",",$row_subcategories);
    if(strlen($subcategories2)>0)
    {
        $subcategories .= ",".$subcategories2;
    }
    $query_product=mysqli_query($connect,"SELECT products.product_id as product_id,
                                    if(products_variants.stock=0,'false','true') as stock,
                                    products.url as url,
                                    products.price as price,
                                    products.large_image as picture,
                                    brands.name as vendor,
                                    products.model as model,
                                    products.body as description,
                                    brands.country as country
                                    FROM products INNER JOIN brands ON products.brand_id = brands.brand_id LEFT JOIN products_variants ON products.product_id=products_variants.product_id
                                    WHERE products.enabled=1 AND products.price<>0 AND products.category_id IN (".$subcategories.")
                                     ");
    while ($row_product=mysqli_fetch_assoc($query_product))
    {
    echo
    "
    <offer id='".$row_product['product_id']."' type='vendor.model' available='".$row_product['stock']."'>
    <url>http://example.com/products/".$row_product['url']."</url>";
    echo "
    <price>".$row_product['price']."</price>
    <currencyId>RUR</currencyId>
    <categoryId>1</categoryId>
    ";
    echo "<picture>http://example.com/files/products/".$row_product['picture']."</picture>
    <delivery>false</delivery>
    <local_delivery_cost>0</local_delivery_cost>
    <typePrefix>Compressor</typePrefix>
    <vendor>".$row_product['vendor']."</vendor>
    ";
    echo "<vendorCode></vendorCode>
    <model>".full_trim($row_product['model'])."</model>
    <description></description>
    <sales_notes></sales_notes>
    <manufacturer_warranty>true</manufacturer_warranty>
    <country_of_origin>".$row_product['country']."</country_of_origin>
    </offer>
    ";
    }
    echo "</offers>
    ";
    echo "</shop>
    </yml_catalog>
    ";
?>

1 个答案:

答案 0 :(得分:-1)

试一试:

$query_product=mysqli_query($connect,"SELECT `products`.`product_id` as product_id,
                                if(`products_variants`.`stock`=0,'false','true') as stock,
                                `products`.`url` as url,
                                `products`.`price` as price,
                                `products`.`large_image` as picture,
                                `brands`.`name` as vendor,
                                `products`.`model` as model,
                                `products`.`body` as description,
                                `brands`.`country` as country
                                FROM `products` INNER JOIN `brands` ON `products`.`brand_id` = `brands`.`brand_id` LEFT JOIN `products_variants` ON `products`.`product_id`=`products_variants`.`product_id`
                                WHERE `products`.`enabled`=1 AND `products`.`price`<>0 AND `products`.`category_id` IN ('$subcategories')");