2013-05-07 79 views
-3

我有一個看起來很簡單的問題,但由於某種原因我無法修復它。也許你可以一眼就解決它。 我有以下腳本。它調用沒有錯誤,但不能正常工作。我將SET請求分爲兩個以更好地解釋問題。我還添加了一些評論,以更好地看。重點是,兩個類似的請求之一不工作...mysql腳本。 SET請求不起作用

include_once ("../php/db_connects.php"); // connect to the database 
$query = mysql_query ('SELECT * FROM articles WHERE status = "1"'); //pick all the lines with status (enum) = 1; 
$row = mysql_fetch_array ($query); // general staff 
do { 
$pluses = $row ['pluses']; 
$minuses = $row['minuses']; 
$link = $row['link']; 

$count = $pluses-$minuses; // checking if article has more positive votes than negaitve 
if($count > 0){ 
mysql_query ('UPDATE articles SET rating = 100 WHERE link = "$link"', $db_conx); 
//the first request works (rating is Int) 
mysql_query ('UPDATE articles SET status = "2" WHERE link = "$link"', $db_conx); 
//the second request doesnt show any mistakes, but it doesn't change status on "2". status is Enum. (ps. there is value of "2" in the database) 
} 
echo "link = " . $link . " count = " . $count; 
}while ($row = mysql_fetch_array ($query)); 

謝謝你的時間。

+1

如果沒有錯誤,那麼找出'$ link'的值並從MySQL GUI運行查詢並找出錯誤。另外,如果不向我們提供變量的值或者不檢查查詢返回值(成功與否),尋求幫助,粘貼代碼以及說些什麼都行不通,從而將猜測可能出錯的可能答案變成可能的答案。 – 2013-05-07 08:13:00

+0

$ link很好,我可以回顯一切,並且第一個SET工作正常,所以$ link很好 – user2331090 2013-05-07 08:14:22

+0

'''mysql_query(「UPDATE ...''''返回什麼嗎? – luksch 2013-05-07 08:15:21

回答

0

我認爲你必須改變這一點:

mysql_query ('UPDATE articles SET rating = 100 WHERE link = "$link"', $db_conx); 
//the first request works (rating is Int) 
mysql_query ('UPDATE articles SET status = "2" WHERE link = "$link"', $db_conx); 

這樣:

mysql_query ("UPDATE articles SET rating = 100 WHERE link = '$link'", $db_conx); 
//the first request works (rating is Int) 
mysql_query ("UPDATE articles SET status = '2' WHERE link = '$link'", $db_conx); 

的原因是,PHP不會取代單引號中的字符串變量。

+0

IT WORKED !!!!我敢打賭,我試過改變「」和「...... omg,非常感謝! – user2331090 2013-05-07 08:24:48

+0

你總是可以upvote ... – luksch 2013-05-07 08:26:31