我有一个看似简单的问题,但由于某种原因我无法修复它。也许你可以一眼就解决它。 我有以下脚本。它没有错误,但无法正常工作。我将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));
感谢您的时间。
答案 0 :(得分: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不会用单引号字符串替换变量。