Hi all, long time visitor, first time poster!
I am new to PHP and have been stuck for a LONG time on the following problem:
I am trying to edit a program which someone else made which gets the current user id and displays correct values for that user id...however, I want it to display all usernames and values.
Here is what I have so far (from the modified code). I made a few aesthetic changes to make it easier to read, which would result in minor errors, but the code is the same I only changes the values for the $userResult variable. The rest get info for the current user_id.:
<?php
$relative_root = "../";
require ("../util/wrapper.php");
//Commented out for testing purposes
/*global $_GET;
$user_id = $_GET["user"];
$can_access = false;
if ($user_id == $GLOBALS["session_user_id"] || $GLOBALS["session_is_admin"] == true)
$can_access = true;
if (!$can_access)
httpRedirect($relativeRoot);
*/
//Gets all the needed info for the current user...
$userResult = dbQuery("SELECT * FROM user");
echo mysql_error();
$userRow = mysql_fetch_assoc($userResult);
$totalResult = dbQuery("SELECT SUM(points) AS total FROM points WHERE user_id=" . $user_id . "GROUP BY user_id");
echo mysql_error();
$totalRow = mysql_fetch_assoc($totalResult);
$totalDie = dbQuery("SELECT SUM(points) AS total FROM points WHERE user_id=" . $user_id . "AND custom_event_id=1
GROUP BY user_id");
echo mysql_error();
$totalE1 = mysql_fetch_assoc($totalDie);
$totalNim = dbQuery("SELECT SUM(points) AS total FROM points WHERE user_id=" . $user_id . "AND custom_event_id=2
GROUP BY user_id");
echo mysql_error();
$totalE2 = mysql_fetch_assoc($totalNim);
$totalTul = dbQuery("SELECT SUM(points) AS total FROM points WHERE user_id=" . $user_id . "AND custom_event_id=3
GROUP BY user_id");
echo mysql_error();
$totalEv3 = mysql_fetch_assoc($totalTul);
$totalLum = dbQuery("SELECT SUM(points) AS total FROM points WHERE user_id=" . $user_id . "AND custom_event_id=4
GROUP BY user_id");
echo mysql_error();
$totalEv4 = mysql_fetch_assoc($totalLum);
$totalBak = dbQuery("SELECT SUM(points) AS total FROM points WHERE user_id=" . $user_id . "AND custom_event_id=5
GROUP BY user_id");
echo mysql_error();
$totalEv5 = mysql_fetch_assoc($totalBak);
$body = "
<p align=\"center\"><font size=\"+2\"><b>Program Name</b></font>:</p>
<BR>
";
$body .= "
<table border=1 cellpadding=2 align=center>
<tr>
<td><b>User</b></td>
<td><b>Total</b></td>
<td><b>Event 1</b></td>
<td><b>Event 2</b></td>
<td><b>Event 3</b></td>
<td><b>Event 4</b></td>
<td><b>Event 5</b></td>
</tr>
";
//This is my own doing:
while ($u_row = mysql_fetch_assoc($userResult))
{
$body .= "<tr>";
$body .= "<td>" . $u_row["char_name"] . "</td>";
}
$totalResult = dbQuery("SELECT SUM(points) AS total FROM points WHERE user_id=" . $u_row["user_id"] . "GROUP BY user_id");
$body .= "<tr>";
$body .= "<td>" . $totalResult["total"] . "</td>";
$body .= "</tr>";
/* Commented out because I am not sure where they go...
* but these are the values I need from each user:
* $body .= "<td>" . $totalResult["total"] . "</td>";
* $body .= "<td>" . $totalEv1["total"] . "</td>";
* $body .= "<td>" . $totalEv2["total"] . "</td>";
* $body .= "<td>" . $totalEv3["total"] . "</td>";
* $body .= "<td>" . $totalEv4["total"] . "</td>";
* $body .= "<td>" . $totalEv5["total"] . "</td>";
*/
$body .= "</tr>";
$body .= "
</table>
";
echo makePage($body);
dbClose();
?>
Alot of things in there are included functions as I am sure you could have guesses.
Again what I want is a table that displays all user names, total amount, event 1 amount, event 2 amount (...) event 5 amount...so 7 columns that need filling in; 1 of which I have done.
I changed some of the names because it isn't my code, but if you would like to help me 1 on 1, or need me to post more here, I will...just ask!
Thanks in advance for the help!