我读一个文本文件,并处理一些记录,文本文件的相关样品为什么使用If语句更改变量?
#export_dategenre_idapplication_idis_primary
#primaryKey:genre_idapplication_id
#dbTypes:BIGINTINTEGERINTEGERBOOLEAN
#exportMode:FULL
127667880285760063715151750
12766788028576
我想执行特定操作时APPLICATION_ID已经与存储在我的数据库中is_primary = 1
我写这个PHP来测试我的代码:
$fp1 = fopen('genre_application','r');
if (!$fp) {echo 'ERROR: Unable to open file.'; exit;}
while (!feof($fp1)) {
$line = stream_get_line($fp1,128,$eoldelimiter); //use 2048 if very long lines
if ($line[0] === '#') continue; //Skip lines that start with #
$field = explode ($delimiter, $line);
list($export_date, $genre_id, $application_id, $is_primary) = explode($delimiter, $line);
// does application_id exist?
$application_id = mysql_real_escape_string($application_id);
$query = "SELECT * FROM jos_mt_links WHERE link_id='$application_id';";
$res = mysql_query($query);
if (mysql_num_rows($res) > 0) {
echo $application_id . "application id has genre_id" . $genre_id . "with primary of " . $is_primary. "\n";
} else
{
// no, application_id doesn't exist
}
} //close reading of genre_application file
fclose($fp1);
导致该输出在屏幕上是完全一样的我的预期。
371515175application id has genre_id6006with primary of 0
371515175application id has genre_id6012with primary of 1
如果我然后添加的IF语句,如下代码,它以某种方式改变了is_primary值如图中的画面显示
$fp1 = fopen('genre_application','r');
if (!$fp) {echo 'ERROR: Unable to open file.'; exit;}
while (!feof($fp1)) {
$line = stream_get_line($fp1,128,$eoldelimiter); //use 2048 if very long lines
if ($line[0] === '#') continue; //Skip lines that start with #
$field = explode ($delimiter, $line);
list($export_date, $genre_id, $application_id, $is_primary) = explode($delimiter, $line);
// does application_id exist?
$application_id = mysql_real_escape_string($application_id);
$query = "SELECT * FROM jos_mt_links WHERE link_id='$application_id';";
$res = mysql_query($query);
if (mysql_num_rows($res) > 0) {
if ($is_primary = '1') echo $application_id . "application id has genre_id" . $genre_id . "with primary of " . $is_primary. "\n";
} else
{
// no, application_id doesn't exist
}
} //close reading of genre_application file
fclose($fp1);
?>
上述代码在下面的屏幕显示的结果,它错误地具有为1的初级的第一场中,当如可通过前一屏幕显示可以看出与示例文本文件应该是0
371515175application id has genre_id6006with primary of 1
371515175application id has genre_id6012with primary of 1
谁能解释我在做什么来改变变量以及我应该如何正确使用If?