Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 928287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:59:13+00:00 2026-05-15T19:59:13+00:00

I am reading a text file and processing some records, a relevant sample of

  • 0

I am reading a text file and processing some records, a relevant sample of the text file is

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

I want to perform a specific action when application_id is already stored within my database AND is_primary = 1

I wrote this PHP to test my code:

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

which results in this output on screen and is exactly as I expected.

371515175application id has genre_id6006with primary of 0

371515175application id has genre_id6012with primary of 1

If I then add an IF statement as in the code below, it somehow changes the value of is_primary as shown by the screen display

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

The code above results in the following screen display, which incorrectly has the first field with a primary of 1, when as can be seen by the previous screen display and the sample text file it should be 0

371515175application id has genre_id6006with primary of 1

371515175application id has genre_id6012with primary of 1

Can anyone explain what I am doing to make the variable change and how I should use the If correctly please?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T19:59:14+00:00Added an answer on May 15, 2026 at 7:59 pm

    You are assigning a value instead of comparing:

    ($is_primary = '1')

    you need

    ($is_primary == '1')

    or === for a type-safe comparison.

    This is why some people like to write their comparisons like so:

    ('1' == $is_primary)

    the mistake is impossible to make here because “1” can’t be assigned anything.

    Personally though, I think that over time and with growing practice, one will learn to spot the mistake.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 448k
  • Answers 448k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This was what I came up with: req = mechanize.Request("https://www.site.com/path/"… May 15, 2026 at 8:00 pm
  • Editorial Team
    Editorial Team added an answer It is an oversight in the RichTextBox class. Other controls,… May 15, 2026 at 8:00 pm
  • Editorial Team
    Editorial Team added an answer That weird deeply recursive breakpoint you're seeing looks like you're… May 15, 2026 at 8:00 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.