Hi,
I am driving myself mad with getting this to work. Basically i have a page see below:
http://www.freemanholland.com/babies/your-recommendations/
You will need to login via the link in the “SIGN UP FREE TODAY!” box at the top, with joe@hotmail.com, and password.
Thought i would create a test account so you can see exactly what the problem is.
So you will see a series of recommendations, and on the right of each a box which either allows the user to like the recommendation view or see that they already like the recommendation…
What i need to do is check to see if the CURRENT person who is logged in likes the recommendation. But it does not work…
I have the following methods:
public function selectAllApprovedRecommendations(){
$sql = "SELECT
r.ID as theID, r.title, r.review, r.date_added as theDate,
m.fname, m.sname,
COUNT(h.RID) AS HITS, h.UID as theUser
FROM tbl_recommendations r
LEFT JOIN tbl_members m ON r.UID = m.ID
LEFT JOIN tbl_recommendationshits h ON r.ID = h.RID
WHERE r.deleted = 0 AND r.approved = 1 AND m.deleted = 0
GROUP BY r.ID, r.title, r.review, r.date_added, m.fname, m.sname
ORDER BY r.date_added DESC";
$result = mysql_query($sql);
return $result;
}
public function selectAllApprovedRecommendationsHits($RID){
$sql = "SELECT * FROM tbl_recommendationshits WHERE RID = $RID";
$result = mysql_query($sql);
return $result;
}
Now i try to check to see if the SESSION[‘ID’] is the same as $hits[‘UID’], if so show a message, if not show the box which allows users to click to love the recommendation…
<?
$bubbles = Recommendations::selectAllApprovedRecommendations();
$i = 0;
while($row = mysql_fetch_array($bubbles)){
$date = $row['theDate'];
$date = strtotime($date);
$thedate = date("M d, Y \\at h:i:s a",$date);
?>
<div class="recommendation-bubble-wrap">
<div class="right">
<?
$bubbles_hits = Recommendations::selectAllApprovedRecommendationsHits($row['theID']);
$hits_rows = mysql_num_rows($bubbles_hits);
if($hits_rows == 0) {
?>
<form method="post" action="">
<input type="submit" name="updatehits" id="updatehits" class="hits" value=""/>
<input type="hidden" name="ID" value="<?=$row['theID']?>" />
</form>
<?
} else {
while($hits = mysql_fetch_array($bubbles_hits)){
if($hits['UID'] == $_SESSION['ID']) {
?>
<div class="youlikethis"><strong>You like this review</strong></div>
<? } else { ?>
<form method="post" action="">
<input type="submit" name="updatehits" id="updatehits" class="hits" value=""/>
<input type="hidden" name="ID" value="<?=$row['theID']?>" />
</form>
<? }
}
}?>
</div>
<div class="recommendation-bubbles<?=$i?>">
<div class="right heart">
<img src="http://<?=$_SERVER['SERVER_NAME'].$sitename?>images/heart.png" alt="">
<?=$row['HITS']?> people love this too
</div>
<p><?=$row['fname'].' '.$row['sname']?> wants to recommend a <strong> <?=$row['title']?></strong></p>
<strong><?=$thedate?></strong>
<div class="recommendation-text"><?=$row['review']?></div>
</div>
</div>
<?
$i++;
$i = $i % 2;
} ?>
The code above is what i am trying to check, but it doesn’t seem to work, i record the number of hits in a separate table so i had to nest the while loop. But when 2 users like the same review i get this:
http://freemanholland.com/babies/images/test.jpg
So this is not right, this user likes the review, so shouldn’t see the box below it…
Any ideas what i’m doing wrong?
Thanks