I want to listing the zero value too, on three table with foreign key

I using three table with foreign key, the in first table I add the fullname, and in second table I add product, and in three table I add the id number for both tables (first and second).

I want to list the fullname even if they don’t have products

my code

$i = 1;
$qry = $conn->query("SELECT first.*, second.* FROM first JOIN three ON first.id = three.fullnameid
JOIN second ON second.id = three.careedid order by second.id desc ");
while($row= $qry->fetch_assoc()):
<th class="text-center"><?php echo $i++ ?></th>
<td><b><?php echo htmlentities($row['name']); ?></b></td>
<td><b><?php echo htmlentities($row['surname']); ?></b></td>	
<td><b><?php echo htmlentities($row['career']); ?></b></td>					
<?php endwhile; ?>

You would use a LEFT JOIN to get all the matching rows in the left table, regardless of any matching rows in the right table(s).

1 Like

Thank you for your response, I have 8,119 entries, but I get 6435 entries, and there are about 1,700 entries that do not appear. what is the reason. I couldn’t recognize him

I suspect a data problem, perhaps trailing spaces. If you want to PM me a SQL dump of your DB I will take a look at it.

Thank you for your response, i solved the problem

It is considered good form to share what you did to fix the problem for the benefit of all who come to your thread.

1 Like

I cleaned the mysql, the problem is fixed

Sponsor our Newsletter | Privacy Policy | Terms of Service