JOIN 3 different tables display list

1

Good morning.

I'm trying to joke 3 tables and display in a list, but I'm not getting it. I've drawn (with LESS LINES) the tables in the database and an idea of how I'm trying to list the fields.

IthinkthatforthisIshoulddo3joins,butitisnotworking.

$i=0;$result=mysql_query("SELECT * FROM payment 
LEFT JOIN booking ON payment.booking_id = booking.id 
LEFT JOIN customer ON booking.customer_id = customer.id
WHERE (date >= '$datainicialsql' AND date <= '$datafinalsql') ORDER BY date") or die(mysql_error());

while ($linha = mysql_fetch_array($result)) {
    $contador = $i;
    $vcustomer = $linha["customer.name"];
    $vtype = $linha["type"];
    $vdate = date("d-m-Y", strtotime($linha["date"]));

    $vvalue = $linha["amount"];

    echo $i . $customer . " Name: $vcustomer" . " - " . " Date: $vdate" . " Type: $vtype" . " Date: $vdate" . " Amount: $vvalue" .  "<br>";
    $i++;
}
    
asked by anonymous 02.05.2015 / 18:07

1 answer

5

If I understand what you want, what is missing is to add the name column of the Customer table to <

$result = mysql_query("SELECT customer.name, type, date, amount FROM payment 
LEFT JOIN booking ON payment.booking_id = booking.id 
LEFT JOIN customer ON booking.customer_id = customer.id
WHERE (date >= '$datainicialsql' AND date <= '$datafinalsql') ORDER BY date") or die(mysql_error());
    
02.05.2015 / 18:12