Php, outputting the contents of a complex mysql call to a table
Alright, so I've been yelled at for making q开发者_StackOverflowuestions too long, and too short, so I'll try to find a happy medium here.
I've been helping a friend make a raid-attendance tracker for his guild in an mmo game. I recently completed the work with the help of someone else, but somehow screwed up the code along the way without any kind of backups available to me.
The essential idea of the database is this: There's the users database which holds the username, datecreated, rTotal, and rAttend columns. rAttend is incremented if they attend a raid. There is another table called raid that simply holds the date / id of a raid. Lastly there is a 3rd and final table that holds usernames and dates.
The script works something like this, an html page passes all the usernames that showed up to raid, and adds the date into the raid table. The mysql query that I have is supposed to check a user, and for each raid display the time of raid, membername, and whether he went or not, if the result is null, they missed that raid, if it's not, they went.
Without further adieu...Here's the query: ($v_member is sanitized prior to this when the variable is set, it is set via post)
@mysql_select_db($database) or die( "Unable to select database");
$query = "SELECT DISTINCT
r.rDate,
CASE
WHEN a.userName IS NULL THEN 'No'
ELSE 'Yes'
END AS Attended
FROM raids r LEFT JOIN (SELECT UserName, rDate FROM attend WHERE UserName='$v_member') a ON r.rDate=a.rDate
WHERE r.rDate > (SELECT dateCreated FROM users WHERE UserName='$v_member')
ORDER BY r.rDate ASC";
I was wondering how I can take the results from that query, and simply set up a loop with the 2 variables it should be extracting.
$f1=$result['rDate'];
$f2=$v_member;
$f3=$result['Attended'];
If anyone can help with this I would really appreciate it, as I broke something along the way and I have no idea what...Thanks!
while($a = mysql_fetch_assoc($query_result)) {
echo = $a['rDate'];
}
精彩评论