Hello
I have another problem. Here is previous thread: http://www.daniweb.com/forums/post1237196.html#post1237196
and my code:
$tipster = mysql_query("SELECT SUM(Analysis.Profit), Users.id, Users.Country_name, Users.Username, User_status.id_status
FROM Users
INNER JOIN User_status
ON Users.User_status_name=User_status.user_status
left outer JOIN Analysis
ON Users.Username=Analysis.Tipster
WHERE User_status.id_status>=3
GROUP BY Tipster
ORDER BY SUM(Analysis.Profit) DESC");
while ($row = mysql_fetch_array($tipster)) {
$sel_tipster=$row['Username'];
echo "<tr>";
echo "<td>";
echo $sel_tipster;
echo "</td>";
$profit = mysql_query("SELECT SUM(Analysis.Profit), SUM(Analysis.Stake)
FROM Analysis
WHERE Analysis.Tipster='$sel_tipster'
AND Result>0
GROUP BY Tipster
ORDER BY Profit");
echo "<td>";
if (mysql_num_rows($profit)==0) {
echo 0; }
while ($row = mysql_fetch_array($profit)) {
$sel_profit = $row['SUM(Analysis.Profit)'];
echo $sel_profit;
echo "</td>";
}
Now I have all users >= 3 in php table, but if user didn't write any analysis (doesn't exists in table Analysis) he has 0 in php table, but he is at the end of table.
Example:
We have 3 users, one have +5, other -5 and third 0, because he didn't write any analysis yet.
My php table is than:
tipster profit
tipster 1 +5
tipster 2 -5
tipster 3 0
but I want to have this php table:
tipster profit
tipster 1 +5
tipster 3 0
tipster 2 -5
Have you get any idea how to write a code?