mysql - Accessing rows from a mysqli join query in php -
i have following code:
// db connection info set earlier $sql= "select `table_1.id`, `table_2.id`, `potato` `table_1.id` left join `table_2` on `table_1`.`id` = `table_2`.`id_of_other_table`;"; $rows = mysqli_query($connection, $sql); foreach ($rows $row){ $potato = $row["potato"]; $id = $row["table_2.id"]; }
i can't table_2.id. i've tried doing print_r proper format, says it's mysqli object , don't more info that. however, can potato. i'm guessing it's calling syntax issue, i've searched multiple sites (stack , google included) , not found clear answer. so, need instead of
$id = $row["table_2.id"];
?
assign aliases columns same name.
$sql= "select `table_1`.`id` t1_id, `table_2`.`id` t2_id, `potato` `table_1.id` left join `table_2` on `table_2`.`id_of_other_table` = `table_1`.`id`;"; $rows = mysqli_query($connection, $sql); foreach ($rows $row){ $potato = $row["potato"]; $id = $row["t2_id"]; }
Comments
Post a Comment