从临时表中选择时出错

时间:2014-06-09 15:25:44

标签: php mysql

当我在临时表中进行选择时出现以下错误:

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

$row_checkbanned = mysql_fetch_assoc($query_checkbanned);

以下是完整的代码:

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);    

我哪里出错了?

1 个答案:

答案 0 :(得分:1)

您将错误的参数传递给mysql_fetch_assocmysql_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);