PDA

View Full Version : help with sql query...


Killahbyte
11-08-2006, 06:58 PM
Ok we have a team table that holds all our teams and stats. What i am trying to do is have a sql query that will update user table with the stats from team table. But the only thing updating is one column. I need both. Anyone care to help with this problem?

global $db;
$sql = $db->query_first("select * from " . TABLE_PREFIX . "userteam WHERE userteamid=$teamid AND WHERE title=$teamtitle");
if ($sql){
$db->query_write("UPDATE " . TABLE_PREFIX . "user SET teamtitle = '$teamtile' WHERE $teamid=userteamid AND WHERE title=$teamtitle");
}else{
$db->query_write("UPDATE " . TABLE_PREFIX . "user SET teamtitle = 'NULL' WHERE userteamid=$teamid");
}

What is happening is the teamid in user table updates but the teamtitle does not. Where is my error?

KB

Reeve of shinra
11-08-2006, 07:58 PM
You dont need to use an if/else... it would be something like




$sql = $db->query_first("select * from " . TABLE_PREFIX . "userteam WHERE userteamid=$teamid AND WHERE title=$teamtitle");

$db->query_write("UPDATE " . TABLE_PREFIX . "user SET teamtitle = '$teamtile' WHERE $teamid=userteamid AND WHERE title=$teamtitle");

$db->query_write("UPDATE " . TABLE_PREFIX . "user SET teamtitle = 'NULL' WHERE userteamid=$teamid");


1 - read teh fields in the db
2 & 3 - update those fields

You can probably combine those last two queries into one like in your read query...

r007
11-09-2006, 11:39 AM
You also seem to have an error in your 2nd query WHERE clause? (WHERE $teamid=userteamid). Shouldn't it read "WHERE userteamid=$teamid"?