PDA

View Full Version : Duplicate values are echoed



XTSR
10-01-2017, 11:43 AM
So I am getting data from my table and I used a while loop for it but there are duplicates being printed out. How to fix it?
Here is my script/code:

$db= mysqli_connect('localhost', 'root', '', 'dbclientpetinfosys');

if ($db->connect_error) {
die("Connection failed: " . $db->connect_error);
}

$quePetProfile = "SELECT tblPet.strPetID, tblPet.strPetName, tblPet.strSpecies, tblPet.dbltAge, tblPet.strGender, tblBreed.strBreed
FROM tblPet
INNER JOIN tblBreed
ON tblPet.strRegistrationID = tblBreed.strRegistrationID
LEFT JOIN abandoned
ON tblPet.strPetID = abandoned.strPetID
WHERE tblPet.strRegistrationID = '{$_SESSION['RegID']}' AND abandoned.strPetID IS NULL";
$stmtGetPet = mysqli_query($db, $quePetProfile);
while($arrRow2 = mysqli_fetch_array($stmtGetPet)){
echo '<tr>';
echo '<td>'. $arrRow2['strPetID'] .'</td>';
echo '<td>' . $arrRow2['strPetName'] . '</td>';
echo '<td>' . $arrRow2['strSpecies'] . '</td>';
echo '<td>' . $arrRow2['dbltAge'] . '</td>';
echo '<td>' . $arrRow2['strGender'] . '</td>';
echo '<td>' . $arrRow2['strBreed'] . '</td>';
echo '</tr>';
}

Deadweight
10-03-2017, 09:06 PM
This is because of your left join. You most likely have multiple tblPet.strPetID = abandoended.strPetID.