How to use Inner Join in php?

Asked

Viewed 1,275 times

0

Can someone help me? I have the following problem: I have 2 tables and in these 2 tables I have the names, and in the course table I have nome and in the category table I also have the field nome. My question is this: how do I do it in the PHP? I’m trying to do it like this:

$sql = mysqli_query($mysqli, "SELECT cur.nome, cat.nome FROM cursos cur INNER JOIN categorias cat ON cur.id_curso = cat.id WHERE cat.id = '$id_categoria'");
$row = mysqli_fetch_array($sql);

After that, I don’t know how I select either the course name or the category name. Could anyone help me?

  • 4

    This has nothing to do with php, this is sql

  • You can set an alias for the fields cur.nome, cat.nome thus: cur.nome AS nomeTabelaX, cat.nome AS nomeTabelaY

  • 1

    would look something like this? SELECT cur.nome AS curso, cat.nome AS categoria FROM...?

  • intendi intao thank you for the reply

  • 1

    related also: http://answall.com/questions/65624/dados-countercountercountercom-inner-join-utilizando-pdo

No answers

Browser other questions tagged

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