2012-01-28 46 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()); 
} 
相關問題