My aim is to show/display in the right part questions of the survey (from a table of my database) and in the left part answers from customers (from another table in my database) in the right part. So my question is : How to merge this two select query ? I did some research but with php it's kind of tricky to understand and I'm still new on php too. Any help or advices are welcome .
Best Regards AV
<?php
include("bdconnect_Foredeck.php");
$link=mysqli_connect($host,$login,$pass,$dbname);
if(isset($_POST["bouton55"])){
$link = mysqli_connect($host,$login,$pass,$dbname);
$id = $_REQUEST["Zoubi"];
$ClientRef =$_REQUEST["KGB"];
$rechercheq = "SELECT Qref,Ref,Question FROM questionnaire WHERE Qref ='$id' ";
$recherche= "SELECT choix,commentaire FROM reponse WHERE RefQ ='$id' and ref_Client ='$ClientRef'";
mysqli_query($link,$recherche);
mysqli_query($link,$rechercheq);
$result1=mysqli_query($link,$rechercheq);
$result= mysqli_query($link,$recherche);
while($row = mysqli_fetch_assoc($result,$result1)){
$Ref =$row["Ref"];
$Question =$row["Question"];
$Choix =$row["choix"];
$Commentara =$row["commentaire"];
echo" <tr bgcolor=\"white\">
<td> $id </td>
<td> $Ref </td>
<td>$Question </td>
<td>$Choix </td>
<td>$Commentara </td>
</tr>";
}
}
?>
You could use a JOIN
SELECT a.Qref, a.Ref,a.Question , b.choix, b.commentaire
FROM questionnaire as a
LEFT JOIN reponse as b ON a.RefQ = b.RefQ
WHERE a.Qref ='$id'
AND b.ref_Client ='$ClientRef'
if you have duplicated rows .. then you can use distinct
SELECT DISTINCT a.Qref, a.Ref,a.Question , b.choix, b.commentaire
FROM questionnaire as a
LEFT JOIN reponse as b ON a.RefQ = b.RefQ
WHERE a.Qref ='$id'
AND b.ref_Client ='$ClientRef'
otherwise you logic don't permit a single query
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.