Jump to content

[SOLVED] count syntax is wrong


sw9

Recommended Posts

Hi Everybody,

 

I am trying to do something simple and am just messing it up. I am pulling data from a file and then inserting / updating my db with it. I want to use a counter so that if the data id number is the same as the data set before it, it will skip the processing.

 

But I don't seem to be writing that part correctly. Here is my code:

 

<?php 

$fields = array('myid', 'episode_number', 'episode_name', 'secondary_name', 'series_id', 'category', 'subcategory', 'first_run', 'active', 'length', 'notes', 'ep', 'source','pdate', 'adate', 'purchase_date', 'exp_date', 'distributor', 'msn', 'msn_description', 'msn_program_type', 'msn_status', 'msn_filename');
$handle = fopen("VLM_master.txt", "r");
$counter = 1;
while (($data = fgetcsv($handle, 10000, "	")) !== FALSE) {
   
   $data = array_combine($fields, $data);
   $reduced = $counter -1;

if($data['myid'][$counter] != $data['myid'][$reduced]) {
// processing goes here
}
$counter++;
} // end in file
fclose($handle);
?>

 

Any help is much appreciated!

sw

Link to comment
https://forums.phpfreaks.com/topic/112057-solved-count-syntax-is-wrong/
Share on other sites

$data will be over-written with the new row of data...keep the ID in a separate variable:

 

<?php 

$fields = array('myid', 'episode_number', 'episode_name', 'secondary_name', 'series_id', 'category', 'subcategory', 'first_run', 'active', 'length', 'notes', 'ep', 'source','pdate', 'adate', 'purchase_date', 'exp_date', 'distributor', 'msn', 'msn_description', 'msn_program_type', 'msn_status', 'msn_filename');
$handle = fopen("VLM_master.txt", "r");
$last_id = null;
while (($data = fgetcsv($handle, 10000, "	")) !== FALSE) {
  $data = array_combine($fields, $data);
  if($data['myid'] != $last_id) {
    $last_id = $data['myid'];
    // processing goes here
  }
} // end in file
fclose($handle);
?>

Hi, thanks for the help. I will try to better explain....this didn't solve my problem.

 

So the data['myid'] variable is an arbitrary id number. It can be '10', '54377', '6109854', etc. I need to check in my loop if the $data['myid'] that I am currently on is equal to the last $data['myid']. If it is, then I want it to skip the processing. Is this possible?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.