N
N
Name2017-09-17 05:01:54
PHP
Name, 2017-09-17 05:01:54

Loop two queries?

There are two queries:
$z1 = $mysqli->query("SELECT iduser, hisuser FROM his WHERE iduser = '{defined id}'");
$z2 = $mysqli->query("SELECT id, text FROM rew WHERE id = hisuser(from top query)'");
doing so

$z1 = $mysqli->query("SELECT iduser, hisuser FROM his WHERE iduser = '{определенный id}'");
while($qwe= $z1->fetch_object()) {   
$f1 = $qwe->iduser;
$f2 = $qwe->hisuser;
echo "$f1 - $f2";
}

how to convert this code so that when outputting this loop echo "$f1 - $f2"; also add $f3
where $f3 is text from the second request, i.e. text'a id is equal to hisuser from the first request Thank you
:)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
Camaro67, 2017-09-17
@User782

All this can be done within a single request, or rather, you need to do it within a single request.

SELECT `h`.`iduser`, `h`.`hisuser`, `r`.`id`, `r`.`text`
FROM `his` AS `h`
INNER JOIN `rew` AS `r` ON `r`.`id` = `h`.`hisuser`
WHERE `h`.`iduser` = {определенный id}

PS And use prepared queries.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question