简体   繁体   中英

Error in select from temporary table

I have the following error when I make a select in a temporary table:

Warning: mysql_fetch_assoc() expects parameter 1 to be resource, string given 

$row_checkbanned = mysql_fetch_assoc($query_checkbanned);

Here is the complete code:

mysql_select_db($database_config, $config);
$query_temptable = "CREATE TEMPORARY TABLE IF NOT EXISTS temp (
id int NOT NULL AUTO_INCREMENT,
player_id int(11) NOT NULL,
team_id int(11) NOT NULL,
newteam_id int(11) NOT NULL, PRIMARY KEY(id))";
$Result1 = mysql_query($query_temptable, $config) or die(mysql_error());


for($i=0; $i < count($_POST['id']); $i++){
$p_id=mysql_real_escape_string($_POST['id'][$i]);
$t_id=mysql_real_escape_string($_POST['hometeam'][$i]); 
$nt_id=mysql_real_escape_string($_POST['teamID'][$i]);
$insertSQLban = "INSERT INTO temp (player_id, team_id, newteam_id) VALUES ('$p_id', '$t_id', '$nt_id')"; 
mysql_select_db($database_config, $config);
$Result1 = mysql_query($insertSQLban, $config) or die(mysql_error());}


$query_checkbanned = ("SELECT temp.player_id FROM temp, f_banned WHERE f_banned.banplayer_id = temp.player_id AND f_banned.bteam_id = temp.team_id GROUP BY temp.player_id ORDER BY temp.player_id ASC");
$checkbanned = mysql_query($query_checkbanned, $config) or die(mysql_error());
$row_checkbanned = mysql_fetch_assoc($query_checkbanned);
$totalRows_checkbanned = mysql_num_rows($checkbanned);    

Where do I go wrong?

You passed the wrong parameter to both mysql_fetch_assoc and mysql_num_rows

$checkbanned = mysql_query($query_checkbanned, $config) or die(mysql_error());
$row_checkbanned = mysql_fetch_assoc($checkbanned);
$totalRows_checkbanned = mysql_num_rows($row_checkbanned);  

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM