2012-01-28 34 views
0

我需要更新表phpbb_points相同phpbb_posts警告:mysql_fetch_assoc():提供的参数不是一个有效的MySQL

这是我的代码

<?php 
    include 'config.php'; 
    $link = mysql_connect($dbhost, $dbuser, $dbpasswd) or die('Could not connect'); 

$db_id = mysql_select_db($dbname) or die('Could not get db'); 
$d = mysql_fetch_assoc(mysql_query("SELECT * FROM phpbb_users ORDER BY id;")); 

mysql_query("UPDATE phpbb_users SET `user_points`='".$d['user_posts']."' WHERE user_id='".$d['user_id']."';") or die(mysql_error()); 
?> 

但它返回此

警告:mysql_fetch_array():提供的参数不是有效的MySQL 结果资源在/ home/** /public_html/forum/point.php on line 7

请帮帮我,谢谢提前

+2

无法在代码中看到该功能。 – yoda 2012-01-28 06:53:03

+0

你在代码中有'mysql_fetch_assoc()'而不是'mysql_fetch_array()'? – 2012-01-28 06:56:14

+0

从SQL中删除分号';'。 BTW mysql_fetch_assoc是mysql_fetch_array的快捷方式。 – 2012-01-28 06:57:56

回答

0

检查$d['user_posts']在你的第二个查询。这是无效的,因为第一个查询很可能会返回多行。

+0

是的,我需要更新所有用户@@ – 2012-01-28 07:03:26

-1

REMOVE分号在该查询

//虚假码

$d = mysql_fetch_assoc(mysql_query("SELECT * FROM phpbb_users ORDER BY id;")); 

//真实代码

$d = mysql_fetch_assoc(mysql_query("SELECT * FROM phpbb_users ORDER BY id")); 
+0

谢谢,但它不工作:( – 2012-01-28 07:04:52

+0

你需要检查mysql_fetch_array()错误.....在mysql_fetch_assoc()....有没有错误..或发送完整的编码 – 2012-01-28 07:11:04

0
mysql_fetch_assoc(mysql_query("SELECT * FROM phpbb_users ORDER BY id;")); 

您正在使用(分号)在sql中从sql中删除这个(分号;)。

正确的:

$d = mysql_fetch_assoc(mysql_query("SELECT * FROM phpbb_users ORDER BY id")); 

希望这会工作。

+0

对不起,它不工作,当我删除“ORDER BY ID”,MySQL不返回错误,但它不会更新与我的请求 – 2012-01-28 07:21:52

+0

正确的更新查询:mysql_query(“UPDATE phpbb_users SET'user_points' =' “。$ d ['user_posts']。”'WHERE user_id ='“。$ d ['user_id']。”'“)或die(mysql_error()); – 2012-01-28 07:38:04

0
$d = mysql_query("SELECT * FROM phpbb_users ORDER BY id;"); 

while ($row = mysql_fetch_assoc($d) { 
    mysql_query("UPDATE phpbb_users SET `user_points`='".$row['user_posts']."' WHERE user_id='".$row['user_id']."';") or die(mysql_error()); 
} 
相关问题