Freight Table - District Listing

Asked

Viewed 236 times

0

I have a table called bairro:

inserir a descrição da imagem aqui

I have a table called tabelafrete: inserir a descrição da imagem aqui

I have the following SQL

public function getBairroList()
{       
    $sql = "SELECT * FROM bairro as b Left join tabelafrete as t on b.idBairro = t.idDestino where t.idSaida = 1";
    return $this->db->query($sql)->result();    
}

Where t.idSaida = 1 (1 = exit district)

It works as follows: A run from the Centro neighborhood - Until the Abranches neighborhood, costs by the table, 2 points. Soon, exit = 1, arrival = 2... But while I list all the neighborhoods, appears only what is already filled in the freight table.

I need: LIST all the neighborhoods, even if you have not filled out the fields... so that you do not need to register one by one.

I need it this way: inserir a descrição da imagem aqui Can someone help me?

  • What do you expect to appear in the case of pairs (output, destination) that are not registered? You want to have a rough formula for general cases and add exceptions for traffic, hillside, ...?

  • My intention is to list all the neighborhoods... from the starting point. - Departure: 1 - Neighborhood A, Neighborhood B, Neighborhood C... and in them I will define each value.

  • Why take the where t.idSaida = 1 does not solve your problem?

  • It has thesis, it would solve... however, it lists all the exits and not only of the exit 1. As you can look at the print, I have two exits, 1 and 2, if I take out the Where t.idAs it seeks both exit 1, and exit 2, and it would have to be only the exit 1, in case... if I add, it lists only one record, while I do not register all, does not display in the list.

  • The exit are all the neighborhoods registered in the table neighborhoods, both exit, as destinations, are the same.

1 answer

1


I believe your SQL is something like this:

SELECT * 
FROM bairro as b 
Left join tabelafrete as t on b.idBairro = t.idDestino and t.idSaida = '".$id."

Browser other questions tagged

You are not signed in. Login or sign up in order to post.