Reputation: 7
I have this table: tbl_module_bid
image:
https://i.sstatic.net/4hQBN.png
you see users: Ali2,Ali,blackbone,dickface,mhmd let's call for each one of them it's called $player and the sql query I wanna use in:
mysql_query("UPDATE `bbcsystem`.`tbl_admin` SET games_played = games_played + 1 WHERE username = $player");
I tried using this script below:
//Update Game Played (not working very good):
$num_qry = "Select DISTINCT * From tbl_module_bid where user = '".$_SESSION['LOGIN_BALANCE_FRONT']['name']."' AND module = '$mod_id' order by bid asc";
$get_pick = $db->get_results($num_qry,ARRAY_A);
foreach($get_pick as $arr_pic)
{
$player = $arr_pic['user'];
mysql_query("UPDATE `bbcsystem`.`tbl_admin` SET games_played = games_played + 1 WHERE username = $player");
}
Well, the what im trying to do is, Take all the Usernames in tbl_module_bid and for each user inside of the table, I shall update his info (games Played) in another table, im really new to stackoverflow and phpp.. Please Consider Helping my as a big favor to me :) Thanks.
Upvotes: 1
Views: 82
Reputation: 1398
If @Filipe got it right then here is a clean version
<?php
$q = 'UPDATE tbl_admin AS a'
.' INNER JOIN tbl_module_bid AS b ON a.username=b.user'
.' SET a.games_played=games_played + 1 WHERE b.module = "'.$mod_id.'"';
$result = mysql_query($q);
don't forget to mark his answer as the answer
Upvotes: 0
Reputation: 21657
Try something like this:
UPDATE tbl_admin a
INNER JOIN tbl_module_bid b on a.username = b.user
SET a.games_played = games_played + 1
WHERE b.user = $_SESSION['LOGIN_BALANCE_FRONT']['name']
AND b.module = $mod_id
This does your both queries in one single query.
Upvotes: 1