-1

I should enter another query to get the data from another table, how to do it?

first query

$actor_id = $_GET["id"];
$nome= $row ['nome'];
$sql = "select * from gallery WHERE actor_id_fk=". $actor_id;
$rs = mysqli_query($conn, $sql); 

to be included in the code

$sql = "select * from actor WHERE actor_id=". $actor_id;
GMB
  • 216,147
  • 25
  • 84
  • 135
Alex
  • 19
  • 4
  • 3
    Hi, start by looking up the JOIN syntax in your favourite SQL manual or tutorial site – RiggsFolly Jun 17 '20 at 20:47
  • 2
    You also should look at parameterizing your query. This is open to SQL injections. To join to unrelated `selects` a `union` would be used, they require the same number of columns being selected. Since these tables are relate a `join` should be used. – user3783243 Jun 17 '20 at 20:47

1 Answers1

1

That's a simple join:

select *              -- better enumerate the columns here that use "*"
from actor a
inner join gallery g on g.actor_id_fk = a.actor_id
where a.actor_id = ?  -- and better use prepared statements!
GMB
  • 216,147
  • 25
  • 84
  • 135
  • `WHERE actor_id_fk=". $actor_id` `WHERE actor_id=". $actor_id` how to do? sorry I'm not a programmer – Alex Jun 17 '20 at 20:51
  • @Alex: the `on` clause of the `join` matches rows between the two tables. You just need to replace the `?` with your `$actor_id` parameter. – GMB Jun 17 '20 at 20:52
  • ok, try, Thank you – Alex Jun 17 '20 at 20:54
  • I should get this field from the actor table to pass it into the variable `$nome= $row ['nome'];` – Alex Jun 17 '20 at 21:06
  • i tried but it doesn't work – Alex Jun 17 '20 at 21:09
  • here is the code https://yadi.sk/d/ncpgUrxUytgNmg – Alex Jun 17 '20 at 21:12
  • it doesn't work because it can't find the path, which is in the variable `$nome` `$createDeletePath = "../image_upload/actor/uploads/$nome ($actor_id)/".$getIamgeName;` – Alex Jun 17 '20 at 21:14