sw9 Posted June 26, 2008 Share Posted June 26, 2008 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 More sharing options...
rhodesa Posted June 26, 2008 Share Posted June 26, 2008 $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); ?> Link to comment https://forums.phpfreaks.com/topic/112057-solved-count-syntax-is-wrong/#findComment-575229 Share on other sites More sharing options...
sw9 Posted June 26, 2008 Author Share Posted June 26, 2008 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? Link to comment https://forums.phpfreaks.com/topic/112057-solved-count-syntax-is-wrong/#findComment-575272 Share on other sites More sharing options...
sw9 Posted June 26, 2008 Author Share Posted June 26, 2008 Hi Rhodesa, Sorry, I re read what you wrote (I figured you couldn't be wrong!). It makes sense now. Thanks! Link to comment https://forums.phpfreaks.com/topic/112057-solved-count-syntax-is-wrong/#findComment-575276 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.