1

I am already look closely and see I miss something or not. But idk, still error, I'm already make insert sort of from, depending relationship. but still wrong, here, my code

$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
        ");

and this is my tables enter image description here

this is my error

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

this is my function

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;
    }

EDIT : the error is I'm using 3 alias in different join. Even if in same table (thanks to Benjamin Caure, tell me where is my fault)

Ainal Yaqin
  • 31
  • 13
  • https://stackoverflow.com/help/mcve – jarlh Apr 18 '18 at 07:15
  • 1
    Please include at least the error you are seeing. You can not expect the people here to recreate your database based on your diagram and then execute your query. You have to help us to help you :) – Niklas S. Apr 18 '18 at 07:16
  • Your error has nothing to do with your query or your table structure. It is in your PHP code. You need to post that code. – Nick Apr 18 '18 at 07:19
  • The error that you quoted shows, that the problem lies within the code that is in `querywheels()` – please post your underlying PHP code. – Niklas S. Apr 18 '18 at 07:19
  • 2
    Run this query on phpmyadmin and check whtr its giving same error, If no error on phpmyadmin then its an issue with php code – Mangesh Sathe Apr 18 '18 at 07:28

1 Answers1

3

At least I can see this error: you cannot use same alias "p" on different joins, even if it's the same table

    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
Benjamin Caure
  • 2,090
  • 20
  • 27