mysqli_error()由查询引起

时间:2016-08-14 07:06:47

标签: php mysql sql

我有下面的查询,在phpMyAdmin中完全正常,因为我用实际值替换PHP变量。当我的PHP代码中运行此查询时,我最终得到错误:

警告:mysqli_error()要求参数1为mysqli,在 /Applications/AMPPS/www/resources/text/php/get_promoted.php 中给出null 58

第58行:

$result = mysqli_query($con, $sql) or die(mysqli_error($con));

查询:

CREATE TEMPORARY TABLE temp AS (SELECT address_id, address,
        city, state_province, zip_post,
        latitude, longitude, distance
  FROM (
 SELECT z.address_id,
        z.address,
        z.city,
        z.state_province,
        z.zip_post,
        z.latitude, z.longitude,
        p.radius,
        p.distance_unit
                 * DEGREES(ACOS(COS(RADIANS(p.latpoint))
                 * COS(RADIANS(z.latitude))
                 * COS(RADIANS(p.longpoint - z.longitude))
                 + SIN(RADIANS(p.latpoint))
                 * SIN(RADIANS(z.latitude)))) AS distance
  FROM address AS z
  JOIN (   
        SELECT " . $_SESSION['address']['latitude'] . " AS latpoint, " . $_SESSION['address']['longitude'] . " AS longpoint,
                5.0 AS radius,      69.055 AS distance_unit
    ) AS p ON 1=1
  WHERE z.latitude
     BETWEEN p.latpoint  - (p.radius / p.distance_unit)
         AND p.latpoint  + (p.radius / p.distance_unit)
    AND z.longitude
     BETWEEN p.longpoint - (p.radius / (p.distance_unit * COS(RADIANS(p.latpoint))))
         AND p.longpoint + (p.radius / (p.distance_unit * COS(RADIANS(p.latpoint))))
 ) AS d 
 WHERE distance <= radius 
 ORDER BY distance);
 SELECT 
    name AS restaurant, 
    description AS type, 
    address, 
    city, 
    state_province AS county, 
    zip_post AS post,
    ROUND(AVG(rating),0) AS avg_rating,
    ROUND(distance,2) AS distance,
    logo,
    prom.date_created AS promotion_expiry,
    value AS promotion_cost
  FROM temp AS addr
 INNER JOIN restaurant_address AS rest_addr
    ON addr.address_id=rest_addr.address_id
 INNER JOIN restaurant AS rest
    ON rest_addr.restaurant_id=rest.restaurant_id 
 INNER JOIN promotion AS prom
    ON prom.restaurant_id=rest.restaurant_id
 INNER JOIN review AS rev
    ON rest.restaurant_id=rev.restaurant_id
 WHERE distance<delivery_radius GROUP BY restaurant ORDER BY promotion_cost DESC LIMIT 10;

有什么可能导致这个的想法吗?我已经排除了我的mysqli_connect()无法通过输入一个简单的select语句工作的想法,它工作得很好。

0 个答案:

没有答案