Quote:
Originally Posted by Dean C
Oh I see what you mean now, I thought you had a clause on the query to show that info for one team only. Um in that case a better idea would be to run a vB3 cron every 24hours to update the total posts for the team 
|
Well i thought about nicer idea
this is what i made :
PHP Code:
$teamslist = $DB_site->query("
SELECT teams.*,user.username AS username,
user.userid AS userid ,user.posts AS userposts,
user.reputation AS userrep,
COUNT(user.posts) AS totalteamposts,
COUNT(user.reputation) AS totalteamrep
FROM " . TABLE_PREFIX . "teams AS teams
LEFT JOIN user ON(teams.teamid = user.teamid)
WHERE teams.teamid > 1
GROUP BY teams.teamid
");
$teamscount = 0;
while ($teams = $DB_site->fetch_array($teamslist))
{
$teamscount++;
$query .= "UPDATE teams SET posts=$teams[totalteamposts] WHERE teamid=$teams[teamid] \n";
eval('$teamsbit .= "' . fetch_template('teams_teamslistbit') . '";');
}
$DB_site->query($query);
Well this query should work (i dont like the idea of getting updated every 24 hours)
but im getting this error
PHP Code:
Invalid SQL: UPDATE teams SET posts=5 WHERE teamid=2
UPDATE teams SET posts=1 WHERE teamid=3
UPDATE teams SET posts=0 WHERE teamid=4
UPDATE teams SET posts=0 WHERE teamid=5
UPDATE teams SET posts=0 WHERE teamid=6
mysql error: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'UPDATE teams SET posts=1 WHERE teamid=3
UPDATE teams SET posts
when i run this query via phpmyadmin :
[SQL] UPDATE teams SET posts=5 WHERE teamid=2;UPDATE teams SET posts=1 WHERE teamid=3;UPDATE teams SET posts=0 WHERE teamid=4;UPDATE teams SET posts=0 WHERE teamid=5;UPDATE teams SET posts=0 WHERE teamid=6;[/SQL]
im getting this :
[SQL]
our SQL-query has been executed successfully SQL-query:
UPDATE teams SET posts =5 WHERE teamid =2;# MySQL returned an empty result set (i.e. zero rows).
UPDATE teams SET posts =1 WHERE teamid =3;# MySQL returned an empty result set (i.e. zero rows).
UPDATE teams SET posts =0 WHERE teamid =4;# MySQL returned an empty result set (i.e. zero rows).
UPDATE teams SET posts =0 WHERE teamid =5;# MySQL returned an empty result set (i.e. zero rows).
UPDATE teams SET posts =0 WHERE teamid =6;# MySQL returned an empty result set (i.e. zero rows). [/SQL]
so my qustion is what am i doing worng on php so its not working?
i think we very close to get and answer.