user3281831 user3281831 - 10 days ago 4x
PHP Question

Run php mysql query for every row in table

Im trying to create score board for my android app. I have two tables, one table named tabulka with columns:
user_id, name, scoretot, scoreaverage

and another table named statistics with columns:
id, cat_id, user_id, correct, wrong, score, total_question, total_score,tot_time,avg_time, quiz date, datecreated.

In statistics I have stored data for every game users play, so I want to sum all score for each user_id and then REPLACE it to tabulka. Thanks for any help

My not working code looks like this right now:

$queried_users=mysql_query("select user_id from tabulka")

foreach ($queried_users as $user)
$arr = get_single_value(STATISTICS,"sum(score)","user_id='".$user_id.");
foreach ($arr as $entry)
Replace into tabulka (scoretot,user_id);


You could use a single query for update

update tabulka
join (    select user_id, sum(score) as tot 
            from statisctics group by user_id ) t on t.user_id = tabulka.user_id
set tabulka.scoretot = t.tot