Neden ise deyim bir değişkeni değiştirmek kullanarak yapar?

0 Cevap php

Ben metin dosyasının ilgili bir örnek, bir metin dosyası okuma ve bazı kayıtları işliyorum

#export_dategenre_idapplication_idis_primary
#primaryKey:genre_idapplication_id
#dbTypes:BIGINTINTEGERINTEGERBOOLEAN
#exportMode:FULL
127667880285760063715151750
127667880285760123715151751

Application_id zaten benim veritabanı içinde depolanan zaman belirli bir eylemi gerçekleştirmek istediğiniz VE is_primary = 1

Benim kod sınamak için bu PHP yazdı:

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

Hangi ekranda bu çıkışı sonuçlanır ve ben tam beklendiği gibidir.

371515175application id has genre_id6006with primary of 0

371515175application id has genre_id6012with primary of 1

Ben sonra aşağıdaki kodu gibi bir IF deyimi eklerseniz ekran gösterildiği gibi, bu şekilde is_primary değerini değiştirir

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

Yanlış olarak bir önceki ekran ve örnek metin dosyası tarafından görülebilir 1 birincil, ilk alanına sahip aşağıdaki ekran, sonuçların yukarıdaki kod 0 olmalıdır

371515175application id has genre_id6006with primary of 1

371515175application id has genre_id6012with primary of 1

Herkes değişken değişikliği yapmak için ne yapıyorum açıklayabilir ve nasıl If lütfen doğru kullanmak gerekir?

0 Cevap