-3

I have a problem that looks simple, but for some reason I cant fix it. May be you can solve it in one look. I have the following script. It calls no mistakes but doesnt work correctly. I divided the SET request on two to better explanation of the problem. I also added some comments to better look. The point is that one of the two similar requests doesnt work...

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

Thank you for your time.

4

1 回答 1

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 不会替换单引号字符串中的变量。

于 2013-05-07T08:13:21.423 回答