Originally Posted by
Doveman
Thanks to all of you for your suggestions:
I went through each one and here is what I found.
"Your output shows that it added records 4, 5, 6. When you view the database with phpMyAdmin, or console or whatever, what's actually in the table? Does it have 3 STANLEY TOOLS entries?"
When I look at the table in phpMyAdmin all the records are there.
"What happens when you run the whole thing again? Are you getting another 3 new duplicates in the db? Unless there's some unexpected caching going on, your code looks fine."
When I run ther application a 2nd time (w/o clearing the table) it actually finds the records and skips the insert.
"Is there any point in doing trim() around your $data[$manufacturer_sn] var?"
As you can see in the revised code I did that but it made no difference.
"Providing the default values for each of the middle three with the last of true should resolve your issue."
Again as you can see in the revised code I did that but it made no difference.
In the full version of this program I also use the same logic to add products to the products table and products descriptions and that code works perfectly.
In the actual test run there are 100 records. All give the same results. I did notice that when I added the RecordCount echo that all the attempts return a RecordCount of 1 even though it doesn't find the record.
Again THANKS for any help you can give.
>>>>>>>>> HERE IS THE REVISED CODE <<<<<<<<<<
while (($data = fgetcsv($handle, 0, " ",chr(0))) !== FALSE) {
echo chr(13).$data[$manufacturer_sn].chr(13);
$mfsql = "SELECT count(*) as total, manufacturers_id, manufacturers_name FROM " . TABLE_MANUFACTURERS . " WHERE manufacturers_name=\"" . trim($data[$manufacturer_sn]) . "\"";
echo $mfsql.chr(13);
$manufacturers = $db->Execute($mfsql);
echo 'counts '.$manufacturers->fields['total'].chr(13);
echo 'RecordCount '.$manufacturers->RecordCount().chr(13);
echo 'search name '.$data[$manufacturer_sn].chr(13);
echo 'id '.$manufacturers->fields['manufacturers_id'].chr(13);
echo 'name '.$manufacturers->fields['manufacturers_name'].chr(13);
if ($manufacturers->fields['manufacturers_name'] != $data[$manufacturer_sn]) {
echo 'No Match'.chr(13);
$today = date("Y-m-d G:i:s");
$query = "INSERT INTO ". TABLE_MANUFACTURERS ." (manufacturers_name, date_added) VALUES (\"".trim($data[$manufacturer_sn])."\",\"".$today."\")";
echo '$query '.$query.chr(13);
$db->Execute($query, $zf_limit = false, $zf_cache = false, $zf_cachetime=0, $remove_from_queryCache = true);
$manufacturers_id = $db->insert_ID();
echo $manufacturers_id.chr(13);
}
}
>>>>>>> REVISED RESULTS OF ABOVE EXECUTED CODE <<<<<<<
STANLEY TOOLS
SELECT count(*) as total, manufacturers_id, manufacturers_name FROM manufacturers WHERE manufacturers_name="STANLEY TOOLS"
counts 0
RecordCount 1
search name STANLEY TOOLS
id
name
No Match
$query INSERT INTO manufacturers (manufacturers_name, date_added) VALUES ("STANLEY TOOLS","2016-01-02 22:28:23")
4
STANLEY TOOLS
SELECT count(*) as total, manufacturers_id, manufacturers_name FROM manufacturers WHERE manufacturers_name="STANLEY TOOLS"
counts 0
RecordCount 1
search name STANLEY TOOLS
id
name
No Match
$query INSERT INTO manufacturers (manufacturers_name, date_added) VALUES ("STANLEY TOOLS","2016-01-02 22:28:23")
5
STANLEY TOOLS
SELECT count(*) as total, manufacturers_id, manufacturers_name FROM manufacturers WHERE manufacturers_name="STANLEY TOOLS"
counts 0
RecordCount 1
search name STANLEY TOOLS
id
name
No Match
$query INSERT INTO manufacturers (manufacturers_name, date_added) VALUES ("STANLEY TOOLS","2016-01-02 22:28:23")
6
Bookmarks