결과를 검색하는 데이터베이스를 반복하는 데 약간의 문제가 있습니다. 왜 문제가 발생하는지 알지만, PHP를 가장 훌륭하게 사용하지는 못해서 솔루션을 구현하는 방법을 잘 모릅니다. 포럼을 살펴본 결과 문제를 해결할 수있는 정보가 없습니다.PHP mysqli가 너무 많은 결과를 반복 중입니다.
아래에서 내 결과는 12 개의 결과를 내고 싶습니다. 각각의 루프에 대해 12 개의 항목이 12 개의 항목으로 계산되므로 각 항목에 12 개의 항목을 넣으면 12 개의 항목이 중복됩니다. 어떻게하면이 문제를 해결할 수 있을까요?
MyTable1: myTable2:
| ID | Name | | NameID | Details |
|--------|--------| |----------|-------------------|
| 0 | bob | | 0 | lives in the city |
| 1 | david | | 1 | lives in a caravan|
------------------- --------------------------------
내 MSQLI 쿼리 :
$qryRandom = "SELECT MyTable1.ID, MyTable2.Details
FROM MyTable1
INNER JOIN MyTable2
ON MyTable1.ID=MyTable2.NameID
ORDER BY RAND()
LIMIT 6;";
내 PHP (generall 예).
$resultR= $con->query($qryRandom) or die($mysqli->error.__LINE__);
while($row = mysqli_fetch_array($resultR, MYSQL_ASSOC))
{
foreach ($row as $key=>$value){ // loops 12 times here as there is 6 items x 2 values
echo $key.": ".$value."<br>";
}
}
결과 출력 :
bob lives in city
bob lives in city
David lives in caravan
David lives in caravan
john lives in the car
john lives in the car // doubles of each entry is my issue
// hope I was thorough and provided enough info for my scenario.
"일반적인 예"는 자세한 설명과 모순됩니다. 실제 질문이 아닌 전체 질문을 렌더링하는 –
당신이 제공 한 쿼리는 그러한 결과를 산출 할 수 없습니다. –