I'm working on a school project where people can sell their home and also buy homes. I'm trying to make a "favourite" feature, but the first step isn't working 100%. The first step is to make the heart red if the user has saved a house as favourite if the user didn't save the house as favourite, the heart should be grey.
This is the code I use in the while loop where all houses will return, so $detailsHuis['id'] comes from that while loop.
<?php
$huisid = $detailsHuis['id'];
$getFavoriet = "SELECT * FROM favoriet WHERE persoon_id = $gebruikerid AND huis_id = $huisid";
$dataFavoriet = mysqli_query($con, $getFavoriet) or die(mysqli_error($con));
?>
<?php while($detailsFavoriet = mysqli_fetch_assoc($dataFavoriet)): ?>
<?php if($getFavoriet || mysqli_num_rows($getFavoriet) > 0): ?>
<span class="favorite" style="margin-top: 0px; color: #f44336;"><i class="fa fa-heart" style="margin-right: 0px;"></i></span>
<?php else: ?>
<span class="favorite" style="margin-top: 0px;"><i class="fa fa-heart" style="margin-right: 0px;"></i></span>
<?php endif; ?>
<?php endwhile; ?>
When mysqli_num_rows is above 0, I see a red heart next to the house information, but when mysqli_num_rows is below 0, I see no heart next to the house information.
$con is created in config.php
$con = mysqli_connect("localhost","root","kerimbjk","huizenverkoop");
if (!$con) {
echo "Kan geen verbinding maken met MySQL" . PHP_EOL;
echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
exit;
}
I would be nice if someone could help me with this problem.
Edit: Table(favoriet):
+--------------------------+
| id | huis_id | persoon_id|
| 1 | 4 | 2 |
| 2 | 6 | 4 |
+--------------------------+
Table(huis)(full version: http://prntscr.com/bk5zkl):
+------------------------+
| id | prijs | stad |
| 1 | 146521| Amsterdam |
| 2 | 125932| London |
+------------------------+
Table(persoon):
+-----------------------+
| id |username|password |
| 1 | test123|encrypted|
| 2 | demo |encrypted|
+-----------------------+
favoriet means favourite, huis means home, prijs means price, stad means city, persoon means person.
My "house" loop, you can also see the "favourite" loop. I can't past the whole code for some reason, so here it is: http://pastebin.com/Ld2rqcQX