+ 1
how can i join between two tables SQL in php code ?
hi everyone , i have 2 table (session and activity) in the same database , id_session is a primary key in table session and it is a foreign key in table activity how can i write JOIN between this two tables in PHP is this right ? $sql='SELECT * from activity WHERE activity.id_session=seance.id_session '; $req = mysql_query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error());
3 Answers
0
NO !! you should elaborate the join type; is it left join or right join or etc
for understanding what do i mean check this example:
https://www.w3schools.com/sql/sql_join.asp
here is an example :
$query = "SELECT
c.name as category_name,
p.id,
p.category_id,
p.title,
p.body,
p.author,
p.created_at
FROM
myblog.{$this->table} p
LEFT JOIN
categories c ON p.category_id = c.id
ORDER BY
p.created_at DESC
";
if you did'nt get that example i'll write it for you
0
NimaPoshtiban this requete return a table ? If yes , for example how can i select the one of his elements
For example : $sql='SELECT * from $query WHERE id=5 '
Is that correct?
0
NO ,this is not a correct sql syntax