MattClark
04-15-2011, 09:01 AM
My sql statement isn't working on my website, and i was wondering if someone could help me out real quick
"SELECT users.first_name, users.last_name, users.user_id, venues.venue_name, venues.venue_id, venues.venue_location, checkins.checkin_time FROM users, venues, checkins
WHERE users.user_id IN ( $friend_array ) ORDER BY checkins.checkin_time DESC LIMIT 5"
On my website, it's pulling the first name and last name of what appears to be 1 random friend, and a random venue in the venue table..
However, it should be pulling the most 5 recent checkins of people you are friends with, and where they checked in.
Please help! Thanks :)
<?php
// GATHER RECENT FRIEND CHECK INS
$RecentCheckInHistoryList .= "";
if($friend_array != "") {
$RecentCheckInHistoryList = "";
$RecentCheckInHistoryList .='<div id="friendsCheckins" class="contentContainer">
<div class="header">
<p>Friends\' Recent Check-ins</p>
</div> ';
$RecentCheckInHistoryList .= '<div style="padding: 0;" class="grayBox flatTop">';
$sqlCheckin = mysql_query("SELECT users.first_name, users.last_name, users.user_id, venues.venue_name, venues.venue_id, venues.venue_location, checkins.checkin_time FROM users, venues, checkins
WHERE users.user_id IN ( $friend_array ) ORDER BY checkins.checkin_time DESC LIMIT 5") or die ("Sorry, we had a mysql error.");
while($row = mysql_fetch_array($sqlCheckin)) {
$friendFirstName = $row["first_name"];
$friendLastName = $row["last_name"];
$checkintime = $row['checkin_time'];
$checkintime = strftime("%b %d, %Y", strtotime($checkintime));
$venue_name = $row['venue_name'];
$venue_id = $row['venue_id'];
$venue_location = $row['venue_location'];
$value = $row["user_id"];
$check_pic = 'user_photos/' . $value . '/image01.jpg';
if(file_exists($check_pic)) {
$frnd_pic = '<a href="profile.php?id=' . $value . '"><img src="' . $check_pic . '" width="60px" height="60px" border="1" /></a>';
} else {
$frnd_pic = '<a href="profile.php?id=' . $value . '"><img src="user_photos/0/image01.jpg" width="60px" height="60px" border="1" /></a>
';
}
}
$RecentCheckInHistoryList .=' <div class="boxContainer">
<div class="avatar">' . $frnd_pic . '</div>
<div class="content">
<h3><strong><a href="profile.php?id=' . $value . '">' . $friendFirstName . ' ' . $friendLastName . '</a></strong> @ <a href="/venue.php?id=' . $venue_id . '">' . $venue_name . '</a></h3>
<small>' . $venue_location . ' - ' . $checkintime . '</small>
</div>
</div> ';
$RecentCheckInHistoryList .=' </div></div></div>';
} else {
$RecentCheckInHistoryList .='<div id="friendsCheckins" class="contentContainer">
<div class="header">
<p>Friends\' Recent Check-ins</p>
</div> <div style="padding: 0;" class="grayBox flatTop">
<div class="boxContainer">Add friends to be able to see their most recent checkins!
</div></div></div>';
}
?>
"SELECT users.first_name, users.last_name, users.user_id, venues.venue_name, venues.venue_id, venues.venue_location, checkins.checkin_time FROM users, venues, checkins
WHERE users.user_id IN ( $friend_array ) ORDER BY checkins.checkin_time DESC LIMIT 5"
On my website, it's pulling the first name and last name of what appears to be 1 random friend, and a random venue in the venue table..
However, it should be pulling the most 5 recent checkins of people you are friends with, and where they checked in.
Please help! Thanks :)
<?php
// GATHER RECENT FRIEND CHECK INS
$RecentCheckInHistoryList .= "";
if($friend_array != "") {
$RecentCheckInHistoryList = "";
$RecentCheckInHistoryList .='<div id="friendsCheckins" class="contentContainer">
<div class="header">
<p>Friends\' Recent Check-ins</p>
</div> ';
$RecentCheckInHistoryList .= '<div style="padding: 0;" class="grayBox flatTop">';
$sqlCheckin = mysql_query("SELECT users.first_name, users.last_name, users.user_id, venues.venue_name, venues.venue_id, venues.venue_location, checkins.checkin_time FROM users, venues, checkins
WHERE users.user_id IN ( $friend_array ) ORDER BY checkins.checkin_time DESC LIMIT 5") or die ("Sorry, we had a mysql error.");
while($row = mysql_fetch_array($sqlCheckin)) {
$friendFirstName = $row["first_name"];
$friendLastName = $row["last_name"];
$checkintime = $row['checkin_time'];
$checkintime = strftime("%b %d, %Y", strtotime($checkintime));
$venue_name = $row['venue_name'];
$venue_id = $row['venue_id'];
$venue_location = $row['venue_location'];
$value = $row["user_id"];
$check_pic = 'user_photos/' . $value . '/image01.jpg';
if(file_exists($check_pic)) {
$frnd_pic = '<a href="profile.php?id=' . $value . '"><img src="' . $check_pic . '" width="60px" height="60px" border="1" /></a>';
} else {
$frnd_pic = '<a href="profile.php?id=' . $value . '"><img src="user_photos/0/image01.jpg" width="60px" height="60px" border="1" /></a>
';
}
}
$RecentCheckInHistoryList .=' <div class="boxContainer">
<div class="avatar">' . $frnd_pic . '</div>
<div class="content">
<h3><strong><a href="profile.php?id=' . $value . '">' . $friendFirstName . ' ' . $friendLastName . '</a></strong> @ <a href="/venue.php?id=' . $venue_id . '">' . $venue_name . '</a></h3>
<small>' . $venue_location . ' - ' . $checkintime . '</small>
</div>
</div> ';
$RecentCheckInHistoryList .=' </div></div></div>';
} else {
$RecentCheckInHistoryList .='<div id="friendsCheckins" class="contentContainer">
<div class="header">
<p>Friends\' Recent Check-ins</p>
</div> <div style="padding: 0;" class="grayBox flatTop">
<div class="boxContainer">Add friends to be able to see their most recent checkins!
</div></div></div>';
}
?>