billy_111 Posted June 23, 2010 Share Posted June 23, 2010 Hi, I am driving myself mad with getting this to work. Basically i have a page see below: http://freemanholland.com/babies/your-recommendations/ You will need to login via the link in the "SIGN UP FREE TODAY!" box at the top, with [email protected], 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 method: 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; } Now i try to check to see if the SESSION['ID'] is the same as $hits['theUser'], 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"> <? if($row['HITS'] == 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 { if($row['theUser'] != $_SESSION['ID']){ ?> <form method="post" action=""> <input type="submit" name="updatehits" id="updatehits" class="hits" value=""/> <input type="hidden" name="ID" value="<?=$row['theID']?>" /> </form> <? } else { ?> <div class="youlikethis"><strong>You like this review</strong></div> <? } }?> </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; } ?> But it works only when one users likes a recommendation, when a different user is logged in then it shows the button regardless of whether the user has already clicked it.. This is my table structure: tbl_recommendations ID (Auto Inc) UID (User ID) title review date_added tbl_recommendationshits ID (Auto Inc) RID (Review ID) UID (User ID) date_added I'm confused as to why it won't work Link to comment https://forums.phpfreaks.com/topic/205599-while-loop-and-check-user-session/ Share on other sites More sharing options...
monkeytooth Posted June 23, 2010 Share Posted June 23, 2010 Your description is a bit broken. I can't say I understand fully what you are intent on doing or trying to do. Link to comment https://forums.phpfreaks.com/topic/205599-while-loop-and-check-user-session/#findComment-1076022 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.