查询错误,但我不知道它在哪里

时间:2018-04-18 07:14:48

标签: php mysql

我已经仔细观察并看到我错过了什么。但是idk,仍然是错误,我已经从insert那里得到了,取决于关系。但还是错的, 在这里,我的代码

$whls = querywheels("SELECT 
        c.pn_car, pc.pn_partcar, pc.name_partcar, p.name_proses,
        p.name_proses, p.name_proses, tc.cost_total, sp.total_price,
        r.rate_year, sp.total_all FROM secondproses AS sp 

          JOIN proses    AS p  ON sp.proses_1     = p.id_proses
          JOIN proses    AS p  ON sp.proses_2     = p.id_proses
          JOIN proses    AS p  ON sp.proses_3     = p.id_proses
          JOIN toolscost AS tc ON sp.cost_idfk    = tc.cost_id
          JOIN partcar   AS pc ON tc.partcar_idfk = pc.id_partcar
          JOIN car       AS c  ON pc.id_carfk     = c.id_car
          JOIN year_rate AS r  ON tc.rate_idfk    = r.rate_id
        ");

这是我的桌子 enter image description here

这是我的错误

Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result,
boolean given in C:\xampp\htdocs\hwbase\PHP\connect.php on line 17

这是我的功能

function querywheels($sql)
    {
        global $con;
        //query ambil data

    $result = mysqli_query($con,$sql);
    /*$whls = mysqli_fetch_assoc($result);*/
    $rows = [];
        while ($whs = mysqli_fetch_assoc($result)) //this is line 17 
       {
            $rows []= $whs;
            # code...
        }
        return $rows;
    }

编辑:错误是我在不同的连接中使用了3个别名。即使在同一张桌子上(感谢Benjamin Caure,告诉我我的错在哪里)

1 个答案:

答案 0 :(得分:3)

至少我可以看到这个错误:你不能在不同的连接上使用相同的别名“p”,即使它是同一个表

    JOIN proses AS p1 ON sp.proses_1 = p1.id_proses
    JOIN proses AS p2 ON sp.proses_2 = p2.id_proses
    JOIN proses AS p3 ON sp.proses_3 = p3.id_proses