Add values of an inner join to 2 variables

1

I wonder if you have some way to get the results of a separate select through php. I have two foreign keys in the same table, set to the same place, they are tj.fk_time_mandante and tj.fk_time_visitante.

SELECT tt.ds_nome, tti.ds_nome
FROM tb_jogo AS tj INNER JOIN tb_time AS tt ON tj.fk_time_mandante = tt.id_time
INNER JOIN tb_time AS tti ON tj.fk_time_visitante = tti.id_time

I already used mysql_fetch_array but it joins the tt.ds_name and tti.ds_name, I wanted them to be inserted into separate variables Example:

while($row = mysql_fetch_array($sql)){
 echo $row['ds_nome1']; <- para tt.ds_time da consulta
 echo $row['ds_nome2']; <- para tti.ds_time da consulta
}

I have already tested the query in the database, and returned the correct result. Note: I am not using any framework

    
asked by anonymous 23.09.2015 / 02:28

1 answer

3

Give an alias to your columns using AS . This is not from PHP, but rather standard SQL. See more: link

SELECT tt.ds_nome AS ds_nome1, tti.ds_nome AS ds_nome2
FROM tb_jogo AS tj INNER JOIN tb_time AS tt ON tj.fk_time_mandante = tt.id_time
INNER JOIN tb_time AS tti ON tj.fk_time_visitante = tti.id_time
    
23.09.2015 / 02:43