加入2表,其中customer_id = $ username [重复]

I'm developing a laundry service system, using php. I have 2 table, table customer and table ticket (with customer_id as the foreign key here).

so i'm trying to display a list of ticket after the user logged in, consists of data from table customer and table ticket.

i'm trying to join 2 table with customer_id as the link join.. for the logged in username(using $session to store username for logged in customer). here is my code:

$customerusername = $_SESSION['customerusername'];
$result = mysqli_query($conn,"SELECT * from TICKET INNER JOIN CUSTOMER ON TICKET.CUSTOMER_ID=CUSTOMER.CUSTOMER_ID 
                                        WHERE CUSTOMER_ID=(SELECT CUSTOMER_ID from CUSTOMER WHERE CUSTOMER_USER='$customerusername')");

however i got this error Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in this first line below:

while($row = mysqli_fetch_array($result)){   //Creates a loop to loop through results
    $found_row = true;
    echo " <tr>
            <td>".$row['TICKET_ID']."</td>
            <td>".$row['TICKET_PICKUP']."</td>
            <td>".$row['TICKET_PTIME']."</td>
            <td>".$row['TICKET_DELIVERY']."</td>
            <td>".$row['TICKET_DTIME']."</td>
            <td>".$row['TICKET_STATUS']."</td>
            <td>RM ".$row['TICKET_PRICE']."</td>
            <td>".$row['PAYMENT_STATUS']."</td>
            </tr>";
    }
    if ($found_row == false) {
            echo "No Ticket Submitted";
        }

what went wrong?

</div>

You have to use aliases on tables to specify columns that have same names and avoid ambiguous errors.

Your CUSTOMER_ID is present in your two tables. So MySQL cannot know which column you are talking about.

You could try something like this:

$customerusername = $_SESSION['customerusername'];
$result = mysqli_query($conn,
    "SELECT * from TICKET t 
     INNER JOIN CUSTOMER c ON t.CUSTOMER_ID=c.CUSTOMER_ID 
     WHERE t.CUSTOMER_ID=(SELECT CUSTOMER_ID from CUSTOMER WHERE CUSTOMER_USER='$customerusername')");

The second 'CUSTOMER_ID' in the where clause is ambiguous, so the query engine got confused. As @syscall mentioned, you need to alias your tables. Also, you don't need the sub query in the WHERE clause. You already have access to the customer table, so just reference it in your join:

SELECT * 
FROM TICKET t 
JOIN CUSTOMER c ON t.CUSTOMER_ID = c.CUSTOMER_ID 
WHERE c.CUSTOMER_USER='$customerusername'

You don't need an second Select statement in your query. As you allready Join the customer table you can do the following:

$customerusername = $_SESSION['customerusername'];

$result = mysqli_query($conn,
"SELECT * from TICKET t 
 INNER JOIN CUSTOMER c ON t.CUSTOMER_ID=c.CUSTOMER_ID 
 WHERE c.CUSTOMER_USER="'.$customerusername.'")";