Link to home
Start Free TrialLog in
Avatar of helpchrisplz
helpchrisplz

asked on

csv breaking - php

Hi.

i have a script that processes a CSV and is ment to make it have the correct column headings for magento.

For some reason when the script puts the rows to the new CSV, its not outputting the category_ids for certain rows. if you open the fixed csv in excel you can see the row with sku 101059 has its cells messed up.


The category_ids are in the array for every row i can see them by printing out the array.

Its just not putting the catagory id into the fixed CSV correctly and i cant work out why.

please download my full script. I have added some code at line 530 to illustrate what i mean.

christophersowerby.com/csvCleaner.zip

also if you check the printed output from the array you will see that catagory id is not always in the same position for each row. I dont know why this is.
Avatar of Peter Hart
Peter Hart
Flag of United Kingdom of Great Britain and Northern Ireland image

I'm not opening a zip file.
I assume you are using   the PHP "fgetcsv"  - gets a line from the file pointer and parses the CSV fields?   do not use fgets().
and then use fputcsv()


for full details see http://uk3.php.net/fgetcsv  and
http://uk3.php.net/manual/en/function.fputcsv.php
Avatar of helpchrisplz
helpchrisplz

ASKER

index.php

<?php
// this script will remove the crap from the source csv and make it valid

///////////////////////////////////////////////////
// this is how we get the latest CSV file name from the directory.
///////////////////////////////////////////////////
//$dir = "./csv"; 
$dir = "./in";         
$pattern = '/\.(csv|CSV)$/'; // check only file with these ext.          
$newstamp = 0;            
$latestFile = "";

if ($handle = opendir($dir)) {               
       while (false !== ($fname = readdir($handle)))  {            
         // Eliminate current directory, parent directory            
         if (preg_match('/^\.{1,2}$/',$fname)) continue;            
         // Eliminate other pages not in pattern            
         if (! preg_match($pattern,$fname)) continue;            
         $timedat = filemtime("$dir/$fname");            
         if ($timedat > $newstamp) {
            $newstamp = $timedat;
            $latestFile = $fname;
          }
         }
        }
closedir ($handle);



///////////////////////////////////////////////////
// get the csv in an array so we can edit the array
///////////////////////////////////////////////////


error_reporting(E_ALL);

echo '<body><pre><p class="headingText" style="text-align:center;margin-top:7%;font-size:30px;">Please wait... loading CSV rows...</p><div class="hide">';
?>
<script src="https://code.jquery.com/jquery-latest.min.js"
        type="text/javascript"></script>
<script type="text/javascript">     
     $(".hide").css("display", "none");      
</script>
<?php


//$url = "csv/".$latestFile;
$url = "in/".$latestFile;
$fpr = fopen($url, 'r');
if (!$fpr) trigger_error("UNABLE TO READ $url", E_USER_ERROR);

// WITH THE FILE OPENED, READ THE FIRST RECORD
$top = fgetcsv($fpr);

// count($top) is the number of columns
$numcols = count($top);

//echo $numcols;
// DATA ANOMALY: ARRAY POSITION 9 APPEARS TO BE UNCAPTIONED AND UNUSED
$top[9] = 'empty';

// we cant have the duplicate heading names as it will break the array
// so we can append a number to the end of them.

$a = 1;
$b = 1;
$c = 1;
$d = 1;
$e = 1;
$f = 1;
$g = 1;

foreach ($top as &$fixHeadingName)
{

    
    if (strpos($fixHeadingName,'Description') !== false) {
       $fixHeadingName = "short_description";       
    }
    if (strpos($fixHeadingName,'Notepad') !== false) {
       $fixHeadingName = "description";       
    }
    if (strpos($fixHeadingName,'Action') !== false) {
       $fixHeadingName = "store";       
    }
    if (strpos($fixHeadingName,'Web Desc') !== false) {
       $fixHeadingName = "name";       
    }

    if (strpos($fixHeadingName,'Stock Number') !== false) {
       $fixHeadingName = "sku";       
    }
    if (strpos($fixHeadingName,'Quantity') !== false) {
       $fixHeadingName = "qty";       
    }
    // if heading contains Attr Type then add the number to it.
    // becasue we have more than one col named this! and it breaks the array..

    if (strpos($fixHeadingName,'Attr Type') !== false) {
       $fixHeadingName = $fixHeadingName.$a;
       $a++;
    }
    if (strpos($fixHeadingName,'Attr Desc') !== false) {
       $fixHeadingName = $fixHeadingName.$b;
       $b++;
    }
    if (strpos($fixHeadingName,'Attr Format') !== false) {
       $fixHeadingName = $fixHeadingName.$c;
       $c++;
    }
    if (strpos($fixHeadingName,'Attr Code') !== false) {
       $fixHeadingName = $fixHeadingName.$d;
       $d++;
    }
    if (strpos($fixHeadingName,'Attr Value') !== false) {
       $fixHeadingName = $fixHeadingName.$e;
       $e++;
    }
    if (strpos($fixHeadingName,'Avail Stock') !== false) {
       $fixHeadingName = $fixHeadingName.$f;
       $f++;
    }
    if (strpos($fixHeadingName,'Branch') !== false) {
       $fixHeadingName = $fixHeadingName.$g;
       $g++;
    }

    // make headings lowercase
    $fixHeadingName = mb_strtolower($fixHeadingName,'UTF-8');
}

// KEEP ONLY THE LEFTMOST POSITIONS / cols
 $top = array_slice($top,0,16);

// NOW READ THE OTHER RECORDS AND BUILD AN ARRAY OF ASSOCIATIVE ARRAYS
while (!feof($fpr))
{


    // READ THE ROW INTO AN ARRAY
    $cur = fgetcsv($fpr);


    // SKIP EMPTY ROWS
    if (!$cur) continue;

    // COMBINE KEYS AND VALUES
    $cur = array_slice($cur,0,16);
    $out[] = array_combine($top, $cur);
}



//var_dump($out);

// ACTIVATE THIS TO SEE THE ARRAYS
// print_r($out);   

// ACCESS THE DATA IN EACH ARRAY

echo "<h3>This script is reading the CSV and formatting the columns to be valid for magento.</h3>";
//echo "<div><p>once this script has all the column headings + cells displayed correctly we will<br> then write a script to save each row down to a new csv.<br> This CSV will then be ready for upload to the website<br> This will allow us to automate the process</p></div>";
$i = 0; // row counter
foreach ($out as &$cur)
{
    

    // do cat
    //attr type1, category

    $sub_category = $cur['category'];
    $supplier_name_long = $cur['supp name'];
    if(!$supplier_name_long) $supplier_name_long = $cur['supp ref'];
    if($sub_category == "1") $cur = array('category_ids' => "40") + $cur;
    elseif($sub_category == "2") $cur = array('category_ids' => "41") + $cur;
    elseif($sub_category == "3") $cur = array('category_ids' => "47") + $cur;
    elseif($sub_category == "4") $cur = array('category_ids' => "38") + $cur;
    elseif($sub_category == "5") $cur = array('category_ids' => "39") + $cur;
    elseif($sub_category == "6") $cur = array('category_ids' => "42") + $cur;
    elseif($sub_category == "7") $cur = array('category_ids' => "43") + $cur; 
    elseif($sub_category == "8") $cur = array('category_ids' => "44") + $cur;
    elseif($sub_category == "9") $cur = array('category_ids' => "12") + $cur; 
    elseif($sub_category == "10") $cur = array('category_ids' => "18") + $cur;
    elseif($sub_category == "11") $cur = array('category_ids' => "46") + $cur;
    elseif($sub_category == "18") $cur = array('category_ids' => "17") + $cur; 
    elseif($sub_category == "19") $cur = array('category_ids' => "37") + $cur;


    $sub_category = $cur['category_ids'];
    // now we create the product image url from the sku number
    // will look like this: /01-01-008.jpg
    $imageUrl = substr_replace($cur['sku'],"/",0,0);
    $imageUrl = substr_replace($imageUrl,"-",3,0);
    $imageUrl = substr_replace($imageUrl,"-",6,0);
    $imageUrl = substr_replace($imageUrl,".jpg",10,0);

    //create brand new headings
    // add new headings to the array
    // add the modifed varables to the array at pos 1

    $cur = array('thumbnail' => $imageUrl) + $cur;
    $cur = array('small_image' => $imageUrl) + $cur;
    $cur = array('image' => $imageUrl) + $cur;
    $cur = array('store_id' => "0") + $cur;

    $name = $cur['name'];
   // echo "<h4 style='margin: 20px 0 -11px 0'>This is row $i of the CSV</h4>"; echo "<br>";
    //echo strlen(trim($name)); 

    $filledIn = preg_match('/^ *$/', $name);
    if ( $filledIn > 0 && strlen(trim($name)) == 0) {  
        $name = "No name available.";
    }


    $description = $cur['description'];    
    $filledIn = preg_match('/^ *$/', $description);
    if ( $filledIn > 0 && strlen(trim($description)) == 0) {  
        $cur['description'] = "No description available.";
        //echo "string";
    }


    
    $cur = array('product_name' => $name) + $cur;
    $cur = array('name' => $name) + $cur;
 
    



    $price = $cur['price'];
    //$price = "0000000.20";
    //remove zeros from front of price 
    $price = ltrim($price, '0');

    // this will make sure the price has 0000 at the end of the price
    // and if the price is .20 then it will make it 0.2000
    // it seems this is how magento likes the price :/
    $price = number_format($price, 4, '.', '');
    $cur['price'] = $price;

    $reason = $cur['reason']; 
    
    $special_price = '';
                        if(!empty($reason)){

                            $sub_category = $cur['category_ids'];
                            
                            switch($reason){
                                case "25" :
                                    $new_cat = '48,49';
                                    $sub_category = "$sub_category".",".$new_cat;
                                    $take_off = (100 - 75) / 100;
                                    $total = $price * $take_off;
                                    $special_price = ($price - $total);
                                    break;
                                case "50" :
                                    $new_cat = '48,50';
                                    $sub_category = "$sub_category".",".$new_cat;
                                    $take_off = (100 - 50) / 100;
                                    $total = $price * $take_off;
                                    $special_price = ($price - $total);
                                    //if($code == '1402036') exit($special_price);
                                    break;
                                case "70" :
                                    $new_cat = '48,51';
                                    $sub_category = "$sub_category".",".$new_cat;
                                    $take_off = (100 - 30) / 100;
                                    $total = $price * $take_off;
                                    $special_price = ($price - $total);
                                    break;
                                case "10" :
                                    $new_cat = '48,52';
                                    $sub_category = "$sub_category".",".$new_cat;
                                    $take_off = (100 - 90) / 100;
                                    $total = $price * $take_off;
                                    $special_price = ($price - $total);
                                    break;
                                case "35" :
                                    $new_cat = '48,53';
                                    $sub_category = "$sub_category".",".$new_cat;
                                    $take_off = (100 - 65) / 100;
                                    $total = $price * $take_off;
                                    $special_price = ($price - $total);
                                    break;
                            }

                            $cur = array('category_ids' => $sub_category) + $cur;
                        }                       
                  

                        $cur = array('special_price' => $special_price) + $cur;

                      
            $attribute = $cur['attr type1'];
            if(!empty($attribute)){
                // if they have the following attribute then put the produts the the correct magento catagory
                if($attribute == 'GC'){                
                    $sub_category = "$sub_category".",43";                
                }
                switch($attribute){
                case 'SJ':                
                $sub_category = "$sub_category".",54,55";                  
                break;
                case 'LQ':               
                $sub_category = "$sub_category".",54,56";  
                break;
                case 'CW':                
                $sub_category = "$sub_category".",54,57";
                break;
                case 'PB':                
                $sub_category = "$sub_category".",54,58";
                break;
                case 'CB':                
                $sub_category = "$sub_category".",54,59";
                break;
                case 'RC':                
                $sub_category = "$sub_category".",54,60";
                break;
                case 'JF':                 
                $sub_category = "$sub_category".",54,61";
                break;
                case 'SO':                  
                $sub_category = "$sub_category".",54,62";
                break;
                case 'DH':                  
                $sub_category = "$sub_category".",54,63";
                break;
                case 'AA':                 
                $sub_category = "$sub_category".",54,64";
                break;
                case 'KK':                
                $sub_category = "$sub_category".",54,65";
                break;
                case 'UU':                 
                $sub_category = "$sub_category".",54,66";
                break;
                case 'ML':                 
                $sub_category = "$sub_category".",54,67";
                break;
                case 'BR':                  
                $sub_category = "$sub_category".",54,68";
                break;
                case 'CA':                  
                $sub_category = "$sub_category".",69,70";
                break;
                case 'CH':                 
                $sub_category = "$sub_category".",69,71";
                break;
                case 'CR':                  
                $sub_category = "$sub_category".",69,72";
                break;
                case 'DR':                  
                $sub_category = "$sub_category".",69,73";
                break;
                case 'FB':                  
                $sub_category = "$sub_category".",69,74";
                break;
                case 'F4':                 
                $sub_category = "$sub_category".",69,75";
                break;
                case 'IN':                  
                $sub_category = "$sub_category".",69,76";
                break;
                case 'NS':                  
                $sub_category = "$sub_category".",69,77";
                break;
                case 'PO':                  
                $sub_category = "$sub_category".",69,78";
                break;
                case 'TW':                 
                $sub_category = "$sub_category".",69,79";
                break;
                case 'TH':                 
                $sub_category = "$sub_category".",69,80";
                break;
                case 'TU':                  
                $sub_category = "$sub_category".",69,81";
                break;
                case 'UR':                 
                $sub_category = "$sub_category".",69,82";
                break;
                case 'TB':                  
                $sub_category = "$sub_category".",69,83";
                break;
              }
              $cur = array('category_ids' => $sub_category) + $cur;  

            }
           



// disable product if not in stock
$quantity = $cur['qty'];
if ($quantity > 0) {
  $cur = array('status' => "Enabled") + $cur;
} else {
  $cur = array('status' => "Disabled") + $cur;  
}

// add the other crap magento wants.                                             
$cur = array('websites' => "base") + $cur; 
$cur = array('attribute_set' => "Default") + $cur; 

$cur = array('type' => "simple") + $cur;
$cur = array('has_options' => "1") + $cur;
$cur = array('tax_class_id' => "Taxable Goods") + $cur;
$cur = array('visibility' => "Catalog, Search") + $cur;
$cur = array('enable_googlecheckout' => "Yes") + $cur;
$cur = array('is_recurring' => "") + $cur;
$cur = array('manufacturer' => $supplier_name_long) + $cur;
$cur = array('cost' => "") + $cur;
$cur = array('weight' => "") + $cur;        
$cur = array('url_key' => "") + $cur; 
$cur = array('gift_message_available' => "Use config") + $cur; 
$cur = array('meta_title' => "") + $cur; 
$cur = array('meta_description' => "") + $cur; 
$cur = array('custom_design' => "") + $cur; 
$cur = array('page_layout' => "No layout updates.") + $cur; 
$cur = array('options_container' => "Block after Info Column") + $cur; 
$cur = array('image_label' => "") + $cur; 
$cur = array('small_image_label' => "") + $cur; 
$cur = array('thumbnail_label' => "") + $cur; 
$cur = array('url_path' => "") + $cur; 
$cur = array('meta_keyword' => "") + $cur; 
$cur = array('custom_layout_update' => "") + $cur; 
$cur = array('news_from_date' => "") + $cur; 
$cur = array('news_to_date' => "") + $cur; 
$cur = array('special_from_date' => "") + $cur; 
$cur = array('special_to_date' => "") + $cur; 
$cur = array('custom_design_from' => "") + $cur; 
$cur = array('custom_design_to' => "") + $cur; 
$cur = array('min_qty' => "0") + $cur; 
$cur = array('use_config_min_qty' => "1") + $cur; 
$cur = array('is_qty_decimal' => "0") + $cur; 
$cur = array('backorders' => "0") + $cur;
$cur = array('use_config_backorders' => "1") + $cur;
$cur = array('min_sale_qty' => "1") + $cur;
$cur = array('use_config_min_sale_qty' => "1") + $cur;
$cur = array('max_sale_qty' => "0") + $cur;
$cur = array('use_config_max_sale_qty' => "1") + $cur;
$cur = array('is_in_stock' => "0") + $cur;
$cur = array('low_stock_date' => "") + $cur;
$cur = array('notify_stock_qty' => "0") + $cur;
$cur = array('use_config_notify_stock_qty' => "1") + $cur;
$cur = array('manage_stock' => "0") + $cur;
$cur = array('use_config_manage_stock' => "0") + $cur;
$cur = array('stock_status_changed_automatically' => "1") + $cur;
$cur = array('use_config_qty_increments' => "1") + $cur;
$cur = array('qty_increments' => "0") + $cur;
$cur = array('use_config_enable_qty_increments' => "1") + $cur;
$cur = array('enable_qty_increments' => "0") + $cur;
$cur = array('product_name' => "") + $cur;
$cur = array('product_type_id' => "Simple") + $cur;
$cur = array('product_status_changed' => "") + $cur;
$cur = array('product_changed_websites' => "") + $cur;










    $sku = $cur['sku'];
   // echo " and its sku is: ".$sku."<br><br>"; 
    $cur = array('sku' => $sku) + $cur;                         

    $cur = array('store' => "admin") + $cur;  



   
    $i++;
    echo "<h4 style='margin: 20px 0 -11px 0'>Row $i is in the array</h4>";

}

// echo "<br>This is the array before it gets output.<br>";
print_r($out);
  //  echo "//////////////////////////////////////////////////////////////////////////";

$i--;

$mod_date=date("F d Y H:i:s.", filemtime("in/".$latestFile));
echo "<p>Processed CSV with file name: </p><a href='./in/$latestFile'>$latestFile</a> <br><br>This file was uploaded on: $mod_date<br>";




// WRITE A CSV FILE FROM THE ARRAYS
$fpo = fopen('fixedSERVER.CSV', 'w');
if (!$fpo) trigger_error("UNABLE TO WRITE CSV", E_USER_ERROR);
$i = 0; // row counter


foreach ($out as &$cur)
{

    
    // remove bad cols:
    
    unset($cur['empty']); 
    unset($cur['category']); 
    unset($cur['menu']);
    unset($cur['sub menu']);
    unset($cur['supp code']);
    unset($cur['supp name']);
    unset($cur['supp ref']);
    unset($cur['reason']);
    unset($cur['attr type1']);

                            

    if ($i == 0) {      

       $cvsHeadings = array_keys($cur);  
       //print_r($cvsHeadings); 
       fputcsv($fpo, $cvsHeadings); // Write information to the file
       fputcsv($fpo, $cur); // first row will get missed out if we dont output it here
    } else {

      //testing...
      $testStockNumber = $cur['sku'];
      
      if ($testStockNumber == "0101059") { // the offeding row thats breaking
        $testCategory = $cur['category_ids'];
        echo "".$testStockNumber." my category_ids is: |".$testCategory."| but why does this not show in the exported CSV?<br>";
      }

        // now we have the headings in just add ech row
        fputcsv($fpo, $cur); // Write information to the file
    }

    $i++;
}
// ACTIVATE THIS TO SEE THE ARRAYS
print_r($out);
echo "<br><h4>".$i." rows processed</h4>";
echo "your fixed CSV is ready for download:<br>";
?>
<a style="color:red;font-size:19px;line-height: 69px;" class="hide" href="./fixedSERVER.CSV">fixed.CSV</a>

</div>
</body>
<script type="text/javascript"> 

$(document).ready(function () {
  $('.hide').fadeIn(3000);   
  setTimeout(function () {
    $('.headingText').text('Done!');  
  }, 1700);
});        
     
</script>

Open in new window


the CSV:

store,sku,product_changed_websites,product_status_changed,product_type_id,product_name,enable_qty_increments,use_config_enable_qty_increments,qty_increments,use_config_qty_increments,stock_status_changed_automatically,use_config_manage_stock,manage_stock,use_config_notify_stock_qty,notify_stock_qty,low_stock_date,is_in_stock,use_config_max_sale_qty,max_sale_qty,use_config_min_sale_qty,min_sale_qty,use_config_backorders,backorders,is_qty_decimal,use_config_min_qty,min_qty,custom_design_to,custom_design_from,special_to_date,special_from_date,news_to_date,news_from_date,custom_layout_update,meta_keyword,url_path,thumbnail_label,small_image_label,image_label,options_container,page_layout,custom_design,meta_description,meta_title,gift_message_available,url_key,weight,cost,manufacturer,is_recurring,enable_googlecheckout,visibility,tax_class_id,has_options,type,attribute_set,websites,status,category_ids,special_price,name,store_id,image,small_image,thumbnail,short_description,qty,price,description
admin,0101051,,,Simple,,0,1,0,1,1,0,0,1,0,,0,1,0,1,1,1,0,0,1,0,,,,,,,,,,,,,"Block after Info Column","No layout updates.",,,,"Use config",,,,"JOHN R FOX",,Yes,"Catalog, Search","Taxable Goods",1,simple,Default,base,Enabled,"40,54,61",," 18ct White Gold Princess Cut Diamond Ring",0,/01-01-051.jpg,/01-01-051.jpg,/01-01-051.jpg,"18CT PC 0.25 G SI1",000001,995.0000,"This elegant eighteen carat white gold single stone ring is set with a beautiful princess cut diamond weighing 0.25 carats.   The diamond is set in a regular four claw setting. The diamond is G in colour and SI1 in clarity.   This beautiful solitaire is an ideal engagement ring."
admin,0101052,,,Simple,,0,1,0,1,1,0,0,1,0,,0,1,0,1,1,1,0,0,1,0,,,,,,,,,,,,,"Block after Info Column","No layout updates.",,,,"Use config",,,,"JOHN R FOX",,Yes,"Catalog, Search","Taxable Goods",1,simple,Default,base,Enabled,"40,54,61",," 18ct White Gold Princess Cut Diamond Ring",0,/01-01-052.jpg,/01-01-052.jpg,/01-01-052.jpg,"18CT PC 0.37 GVS1",000001,1275.0000,"This elegant eighteen carat white gold single stone ring is set with a beautiful princess cut diamond weighing 0.37 carat is G in colour and VS1 in clarity. The diamond is set in a regular four claw setting. This beautiful solitaire will make a perfect engagement ring."
admin,0101053,,,Simple,,0,1,0,1,1,0,0,1,0,,0,1,0,1,1,1,0,0,1,0,,,,,,,,,,,,,"Block after Info Column","No layout updates.",,,,"Use config",,,,"C WHARTON",,Yes,"Catalog, Search","Taxable Goods",1,simple,Default,base,Disabled,,40," Palladium Single Stone Princess Cut Diamond",0,/01-01-053.jpg,/01-01-053.jpg,/01-01-053.jpg,"PLD P/C DIA GSI1 0.54CT",000000,3050.0000,"This stunning Solitaire made in Palladium features a 0.54 carat Princess cut diamond in a timeless four claw setting to maximize the diamond fire and brilliance. This ring looks beautiful when worn and would make a lovely engagement ring."
admin,0101054,,,Simple,,0,1,0,1,1,0,0,1,0,,0,1,0,1,1,1,0,0,1,0,,,,,,,,,,,,,"Block after Info Column","No layout updates.",,,,"Use config",,,,CORONA,,Yes,"Catalog, Search","Taxable Goods",1,simple,Default,base,Enabled,"40,54,67",," 18ct White Gold 0.40ct Round Diamond",0,/01-01-054.jpg,/01-01-054.jpg,/01-01-054.jpg,"18ct 0.40ct Gsi2 0.10 Hsi",000001,2365.0000,"This beautiful diamond ring features 0.40 carat modern round brilliant cut diamond.  This classic and elegant ring looks beautiful when worn and would make a lovely engagement ring. The diamond is laser inscribed with a personal tracking number, which is unique to you and the diamond"
admin,0101059,,,Simple,,0,1,0,1,1,0,0,1,0,,0,1,0,1,1,1,0,0,1,0,,,,,,,,,,,,,"Block after Info Column","No layout updates.",,,,"Use config",,,,"JOHN R FOX",,Yes,"Catalog, Search","Taxable Goods",1,simple,Default,base,Disabled,," test",0,/01-01-059.jpg,/01-01-059.jpg,/01-01-059.jpg,40,test,000000,4.0000," Re ticked on Sunday 13th after CSV run  Unticked 11.10am Weds 16th Jan2013. Nigel has been advised. Didn't leave the web site.  29th Jan 2013 Stock level re-set to nill.  2 Feb Item gone from web site : Correct. JRF"

Open in new window

this might be obvious but:
index.php finds the CSV by checking a folder called "in"

to test you should create a folder and pop the index.php inside now create the "in" folder inside the same folder that index.php is in.

save the csv down into the in folder.
There is a third party stock control company that gives my the source CSV.

The story behind it can be found here:
https://www.experts-exchange.com/questions/28336931/fix-broken-CSV-extra-quotes.html

The source csv was being truncated by the third party stock system (before it was getting to me) i have contacted the stock company and got them to fix the truncations. but now the php script is playing up when running the new non truncated csv through it.

The php script i pasted here actually works ok with the old truncated CSV i was getting from them. by that i mean if i run the old truncated CSV through the script it will not have the broken catagory_id in the fixed csv - output.


here is a version of the old truncated source CSV i was getting before:

Action,Stock Number,Menu,Sub Menu,Supp Code,Supp Name,Supp Ref,Description,Quantity,,Price,Reason,Category,Web Desc,Notepad,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,,MRRP,Alt Price,Date Created,Branch,Avail Stock,Branch,Avail Stock,Branch,Avail Stock,Branch,Avail Stock,Branch,Avail Stock,Branch,Avail Stock,Branch,Avail Stock,Branch,Avail Stock,Branch,Avail Stock,Branch,Avail Stock,Branch,Avail Stock,Branch,Avail Stock,Branch,Avail Stock,Branch,Avail Stock,Branch,Avail Stock,Branch,Avail Stock,Branch,Avail Stock,Branch,Avail Stock,Branch,Avail Stock,Branch,Avail Stock,
"A","0101008","01","01","0520","JOHN R FOX","FNC336W25","Hi Col Rnd w/g H Si1 .13","000000","","0000410.00","","01","18ct White Gold Round Brilliant Diamond Stacking Ring"," A lovely ring from John R Fox himself, designed to be worn either on it's own, or complimented by another of its kind as a stacking ring. The diamond is 0.13ct round brilliant cut, H colour and SI1 clarity.","JF","John R Fox"          ,"L","01","yes"                           ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,,"0000000.00","0000000.00","12/11/04","Central Stock","000000","157 High Street","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","
"A","0101009","01","01","0520","JOHN R FOX","FNC338W","Hi Col Prin w/g H Si1 .17","000000","","0000570.00","","01","18ct White Gold Princess Cut Diamond Stacking Ring"," A lovely ring from John R Fox himself, designed to be worn either on it's own, or complimented by another of its kind as a stacking ring. The diamond is 0.17ct princess cut, H colour and SI1 clarity.","JF","John R Fox"          ,"L","01","yes"                           ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,,"0000000.00","0000000.00","19/08/08","Central Stock","000000","157 High Street","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","",
"A","0101010","01","01","0520","JOHN R FOX","FNC339W","Hi Col Pear w/g H Si1 .17","000000","","0000350.00","","01"," 18ct White Gold Pear Shaped Diamond Stacking Ring","  A lovely ring from John R Fox himself, designed to be worn either on it's own, or complimented by another of its kind as a stacking ring. The diamond is 0.17ct pear shaped, H colour and SI1 clarity.","JF","John R Fox"          ,"L","01","yes"                           ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,,"0000000.00","0000000.00","12/11/04","Central Stock","000000","157 High Street","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","",
"A","0101011","01","01","0520","JOHN R FOX","FNC340W","Hi Col Bag w/g H Si1 .07","000000","","0000395.00","","01"," 18ct White Gold Baguette Cut Diamond Stacking Ring"," A lovely ring from John R Fox himself, designed to be worn either on it's own, or complimented by another of its kind as a stacking ring. The diamond is 0.07ct baguette cut, H colour and SI1 clarity.","JF","John R Fox"          ,"L","01","yes"                           ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,,"0000000.00","0000000.00","27/07/00","Central Stock","000000","157 High Street","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","",
"A","0101017","01","01","0230","CHUBBIE WH","FNC3W15","Chubbie w/g H Si1 .15","000001","","0000530.00","","01"," Chubbie Eighteen Carat White Gold Single Stone Diamond Ring","This stunning eighteen carat white gold single stone ring is an excellent choice for any lady. One of John Fox's own designs, and a house favourite, this piece is timeless. John has been using it since opening in Guildford over 35 years ago, and it's still going strong!  This is a 0.15 carat round brilliant diamond, H in colour and SI1 in clarity, set in a bezel or rub-over setting.  This is part of the 'Chubbie' collection, and has matching 3, 6 and 16 stone rings, wedding bands, pendants, earrings and a bangle.","CH","Chubbie"             ,"L","01","yes"                           ,"JF","John R Fox"          ,"L","01","yes"                           ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""
"A","0101026","01","01","1800","URSULA","R63043-0","Ursula Prin w/g H Si1 .30","000002","","0000870.00","","01","Ursula Eighteen Carat Princess Cut Diamond Ring","This is a beautiful eighteen carat white gold ring, incorporating a single princess cut diamond held in place using a tension setting.   The diamond is 0.30 carats and is H in colour and SI1 in clarity.   Part of the Ursula collection, this can be matched with a pendant and earrings, and is available in eighteen carat yellow gold.","JF","John R Fox"          ,"L","01","yes"                           ,"UR","Urshula"             ,"L","01","yes"                           ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,,"0000000.00","0000000.00","28/04/03","Central Stock","000000","157 High Street","000002","","00000
"A","0101046","01","01","0230","CHUBBIE WH","FNC4W","Chubbie H Si1 .25","000000","","0000950.00","CR","01","Chubbie Eighteen Carat White Gold Single Stone Ring","This stunning eighteen carat white gold single stone ring is an excellent choice for any lady. One of John Fox's own designs, and a house favourite, this piece is timeless. John has been using it since opening in Guildford over 35 years ago, and it's still going strong!  This is a 0.25 carat round brilliant diamond, H in colour and SI1 in clarity, set in a bezel or rub-over setting.  This is part of the 'Chubbie' collection, and has matching 3, 6 and 16 stone rings, wedding bands, pendants, earrings and a bangle.","CH","Chubbie"             ,"L","01","yes"                           ,"JF","John R Fox"          ,"L","01","yes"                           ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""
"A","0101051","01","01","0520","JOHN R FOX","R1-141","18CT PC 0.25 G SI1","000001","","0000995.00","","01"," 18ct White Gold Princess Cut Diamond Ring","This elegant eighteen carat white gold single stone ring is set with a beautiful princess cut diamond weighing 0.25 carats.   The diamond is set in a regular four claw setting. The diamond is G in colour and SI1 in clarity.   This beautiful solitaire is an ideal engagement ring.","JF","John R Fox"          ,"L","01","yes"                           ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,,"0000000.00","0000000.00","17/11/11","Central Stock","000000","157 High Street","000001","","000000","","000000","","000000","","000000","","000000","","000000",
"A","0101052","01","01","0520","JOHN R FOX","R1-141","18CT PC 0.37 GVS1","000001","","0001275.00","","01"," 18ct White Gold Princess Cut Diamond Ring","This elegant eighteen carat white gold single stone ring is set with a beautiful princess cut diamond weighing 0.37 carat is G in colour and VS1 in clarity. The diamond is set in a regular four claw setting. This beautiful solitaire will make a perfect engagement ring.","JF","John R Fox"          ,"L","01","yes"                           ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,,"0000000.00","0000000.00","17/11/11","Central Stock","000000","157 High Street","000001","","000000","","000000","","000000","","000000","","000000","","000000","","000000"
"A","0101053","01","01","0296","C WHARTON","1Y52A0081R0.50L","PLD P/C DIA GSI1 0.54CT","000000","","0003050.00","D","01"," Palladium Single Stone Princess Cut Diamond","This stunning Solitaire made in Palladium features a 0.54 carat Princess cut diamond in a timeless four claw setting to maximize the diamond fire and brilliance. This ring looks beautiful when worn and would make a lovely engagement ring.",""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,,"0000000.00","0000000.00","13/02/12","Central Stock","000000","157 High Street","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","

Open in new window

Have you tried eliminating this line from the script?
 $top = array_slice($top,0,16);

Open in new window

And this line?
    $cur = array_slice($cur,0,16);

Open in new window

no.  can try. i dont need the data past the 16th column so thats why i havent changed that part. i can give it ago though.
I made those two changes and installed the script here:
http://www.laprbass.com/temp_helpchrisplz/

Got a lot of undefined index messages.  Have a look and see what you think of the resulting CSV.
i think its different because the column ordering has changed when removing the array slice.

e.g: with array slice the category_ids column comes out after the status column
       without the array slice category_ids column comes out after the thumbnail column

with or without the array slice the problem is that the category_ids column should always have something inside of it (and it does if you run the old truncated CSV through it).

if you add the array_slice code back in for testing:
The category_ids don't get put to the csv even though the array has category_ids populated.

Can you see in the code that i have 2 arrays printed out:
one at line 484 and the other at line 542.
They are both the same arrays
but at different points in the code.

If you look at the first array print:
[3] => Array: has category_ids at 20th from the last position.
[4] => Array: has category_ids at 14th from the last position.

If you look at the last array print:
[3] => Array: has category_ids at 11th from the last position.
[4] => Array: has category_ids at 5th from the last position.

Now if you run the truncated CSV data through the script:

If you look at the first array print:
its always at 20th from last position no matter what. (it was 20th and 14th before)

If you look at the last array print:
its always at 11th from last position no matter what. (it was 11th and 5th before)

truncated CSV data:
Action,Stock Number,Menu,Sub Menu,Supp Code,Supp Name,Supp Ref,Description,Quantity,,Price,Reason,Category,Web Desc,Notepad,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,,MRRP,Alt Price,Date Created,Branch,Avail Stock,Branch,Avail Stock,Branch,Avail Stock,Branch,Avail Stock,Branch,Avail Stock,Branch,Avail Stock,Branch,Avail Stock,Branch,Avail Stock,Branch,Avail Stock,Branch,Avail Stock,Branch,Avail Stock,Branch,Avail Stock,Branch,Avail Stock,Branch,Avail Stock,Branch,Avail Stock,Branch,Avail Stock,Branch,Avail Stock,Branch,Avail Stock,Branch,Avail Stock,Branch,Avail Stock,
"A","0101008","01","01","0520","JOHN R FOX","FNC336W25","Hi Col Rnd w/g H Si1 .13","000000","","0000410.00","","01","18ct White Gold Round Brilliant Diamond Stacking Ring"," A lovely ring from John R Fox himself, designed to be worn either on it's own, or complimented by another of its kind as a stacking ring. The diamond is 0.13ct round brilliant cut, H colour and SI1 clarity.","JF","John R Fox"          ,"L","01","yes"                           ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,,"0000000.00","0000000.00","12/11/04","Central Stock","000000","157 High Street","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","
"A","0101009","01","01","0520","JOHN R FOX","FNC338W","Hi Col Prin w/g H Si1 .17","000000","","0000570.00","","01","18ct White Gold Princess Cut Diamond Stacking Ring"," A lovely ring from John R Fox himself, designed to be worn either on it's own, or complimented by another of its kind as a stacking ring. The diamond is 0.17ct princess cut, H colour and SI1 clarity.","JF","John R Fox"          ,"L","01","yes"                           ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,,"0000000.00","0000000.00","19/08/08","Central Stock","000000","157 High Street","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","",
"A","0101010","01","01","0520","JOHN R FOX","FNC339W","Hi Col Pear w/g H Si1 .17","000000","","0000350.00","","01"," 18ct White Gold Pear Shaped Diamond Stacking Ring","  A lovely ring from John R Fox himself, designed to be worn either on it's own, or complimented by another of its kind as a stacking ring. The diamond is 0.17ct pear shaped, H colour and SI1 clarity.","JF","John R Fox"          ,"L","01","yes"                           ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,,"0000000.00","0000000.00","12/11/04","Central Stock","000000","157 High Street","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","",
"A","0101011","01","01","0520","JOHN R FOX","FNC340W","Hi Col Bag w/g H Si1 .07","000000","","0000395.00","","01"," 18ct White Gold Baguette Cut Diamond Stacking Ring"," A lovely ring from John R Fox himself, designed to be worn either on it's own, or complimented by another of its kind as a stacking ring. The diamond is 0.07ct baguette cut, H colour and SI1 clarity.","JF","John R Fox"          ,"L","01","yes"                           ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,,"0000000.00","0000000.00","27/07/00","Central Stock","000000","157 High Street","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","",
"A","0101017","01","01","0230","CHUBBIE WH","FNC3W15","Chubbie w/g H Si1 .15","000001","","0000530.00","","01"," Chubbie Eighteen Carat White Gold Single Stone Diamond Ring","This stunning eighteen carat white gold single stone ring is an excellent choice for any lady. One of John Fox's own designs, and a house favourite, this piece is timeless. John has been using it since opening in Guildford over 35 years ago, and it's still going strong!  This is a 0.15 carat round brilliant diamond, H in colour and SI1 in clarity, set in a bezel or rub-over setting.  This is part of the 'Chubbie' collection, and has matching 3, 6 and 16 stone rings, wedding bands, pendants, earrings and a bangle.","CH","Chubbie"             ,"L","01","yes"                           ,"JF","John R Fox"          ,"L","01","yes"                           ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""
"A","0101026","01","01","1800","URSULA","R63043-0","Ursula Prin w/g H Si1 .30","000002","","0000870.00","","01","Ursula Eighteen Carat Princess Cut Diamond Ring","This is a beautiful eighteen carat white gold ring, incorporating a single princess cut diamond held in place using a tension setting.   The diamond is 0.30 carats and is H in colour and SI1 in clarity.   Part of the Ursula collection, this can be matched with a pendant and earrings, and is available in eighteen carat yellow gold.","JF","John R Fox"          ,"L","01","yes"                           ,"UR","Urshula"             ,"L","01","yes"                           ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,,"0000000.00","0000000.00","28/04/03","Central Stock","000000","157 High Street","000002","","00000
"A","0101046","01","01","0230","CHUBBIE WH","FNC4W","Chubbie H Si1 .25","000000","","0000950.00","CR","01","Chubbie Eighteen Carat White Gold Single Stone Ring","This stunning eighteen carat white gold single stone ring is an excellent choice for any lady. One of John Fox's own designs, and a house favourite, this piece is timeless. John has been using it since opening in Guildford over 35 years ago, and it's still going strong!  This is a 0.25 carat round brilliant diamond, H in colour and SI1 in clarity, set in a bezel or rub-over setting.  This is part of the 'Chubbie' collection, and has matching 3, 6 and 16 stone rings, wedding bands, pendants, earrings and a bangle.","CH","Chubbie"             ,"L","01","yes"                           ,"JF","John R Fox"          ,"L","01","yes"                           ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""
"A","0101051","01","01","0520","JOHN R FOX","R1-141","18CT PC 0.25 G SI1","000001","","0000995.00","","01"," 18ct White Gold Princess Cut Diamond Ring","This elegant eighteen carat white gold single stone ring is set with a beautiful princess cut diamond weighing 0.25 carats.   The diamond is set in a regular four claw setting. The diamond is G in colour and SI1 in clarity.   This beautiful solitaire is an ideal engagement ring.","JF","John R Fox"          ,"L","01","yes"                           ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,,"0000000.00","0000000.00","17/11/11","Central Stock","000000","157 High Street","000001","","000000","","000000","","000000","","000000","","000000","","000000",
"A","0101052","01","01","0520","JOHN R FOX","R1-141","18CT PC 0.37 GVS1","000001","","0001275.00","","01"," 18ct White Gold Princess Cut Diamond Ring","This elegant eighteen carat white gold single stone ring is set with a beautiful princess cut diamond weighing 0.37 carat is G in colour and VS1 in clarity. The diamond is set in a regular four claw setting. This beautiful solitaire will make a perfect engagement ring.","JF","John R Fox"          ,"L","01","yes"                           ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,,"0000000.00","0000000.00","17/11/11","Central Stock","000000","157 High Street","000001","","000000","","000000","","000000","","000000","","000000","","000000","","000000"
"A","0101053","01","01","0296","C WHARTON","1Y52A0081R0.50L","PLD P/C DIA GSI1 0.54CT","000000","","0003050.00","D","01"," Palladium Single Stone Princess Cut Diamond","This stunning Solitaire made in Palladium features a 0.54 carat Princess cut diamond in a timeless four claw setting to maximize the diamond fire and brilliance. This ring looks beautiful when worn and would make a lovely engagement ring.",""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,""  ,""                    ,"" ,""  ,""                              ,,"0000000.00","0000000.00","13/02/12","Central Stock","000000","157 High Street","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","

Open in new window



so what am saying is the arrays are holding data... in the wrong positions and thats why they are not putting the category_ids to the fixed csv correctly i think?

i just don't see how all the category_ids are filled out in the fixed csv when using the old truncated csv but not when using the non truncated csv.
do you see the php echo that says:
"0101059 my category_ids is: |40| but why does this not show in the exported CSV?"

This only shows when the array slice is used.

This php echo illustrates thats the array is holding category_ids = 40 for the row with SKU of 0101059 but when you look at the fixed csv it has nothing in the category_ids for this row and this is why it breaks.

i need to understand why this is not put to the csv when it is in the array. :P
hang on i made a posting error. might be easier to just recreate this question! grr

when i posted the index.php along with the csv i put the wrong csv data.
This is the correct source CSV data. (the non truncated CSV data)

Action,Stock Number,Menu,Sub Menu,Supp Code,Supp Name,Supp Ref,Description,Quantity,,Price,Reason,Category,Web Desc,Notepad,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,Attr Type,Attr Desc,Attr Format,Attr Code,Attr Value,,MRRP,Alt Price,Date Created,Branch,Avail Stock,Branch,Avail Stock,Branch,Avail Stock,Branch,Avail Stock,Branch,Avail Stock,Branch,Avail Stock,Branch,Avail Stock,Branch,Avail Stock,Branch,Avail Stock,Branch,Avail Stock,Branch,Avail Stock,Branch,Avail Stock,Branch,Avail Stock,Branch,Avail Stock,Branch,Avail Stock,Branch,Avail Stock,Branch,Avail Stock,Branch,Avail Stock,Branch,Avail Stock,Branch,Avail Stock,
"A","0101051","01","01","0520","JOHN R FOX","R1-141","18CT PC 0.25 G SI1","000001","","0000995.00","","01"," 18ct White Gold Princess Cut Diamond Ring","This elegant eighteen carat white gold single stone ring is set with a beautiful princess cut diamond weighing 0.25 carats.   The diamond is set in a regular four claw setting. The diamond is G in colour and SI1 in clarity.   This beautiful solitaire is an ideal engagement ring.","JF","John R Fox","L","01","yes","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","",,"0000000.00","0000000.00","17/11/11","Central Stock","000000","157 High Street","000001","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000" ,
"A","0101052","01","01","0520","JOHN R FOX","R1-141","18CT PC 0.37 GVS1","000001","","0001275.00","","01"," 18ct White Gold Princess Cut Diamond Ring","This elegant eighteen carat white gold single stone ring is set with a beautiful princess cut diamond weighing 0.37 carat is G in colour and VS1 in clarity. The diamond is set in a regular four claw setting. This beautiful solitaire will make a perfect engagement ring.","JF","John R Fox","L","01","yes","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","",,"0000000.00","0000000.00","17/11/11","Central Stock","000000","157 High Street","000001","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000" ,
"A","0101053","01","01","0296","C WHARTON","1Y52A0081R0.50L","PLD P/C DIA GSI1 0.54CT","000000","","0003050.00","D","01"," Palladium Single Stone Princess Cut Diamond","This stunning Solitaire made in Palladium features a 0.54 carat Princess cut diamond in a timeless four claw setting to maximize the diamond fire and brilliance. This ring looks beautiful when worn and would make a lovely engagement ring.","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","",,"0000000.00","0000000.00","13/02/12","Central Stock","000000","157 High Street","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000" ,
"A","0101054","01","01","0295","CORONA","3434WG/50-18","18ct 0.40ct Gsi2 0.10 Hsi","000001","","0002365.00","","01"," 18ct White Gold 0.40ct Round Diamond","This beautiful diamond ring features 0.40 carat modern round brilliant cut diamond.  This classic and elegant ring looks beautiful when worn and would make a lovely engagement ring. The diamond is laser inscribed with a personal tracking number, which is unique to you and the diamond","ML","Maple Leaf","L","01","yes","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","",,"0000000.00","0000000.00","28/04/12","Central Stock","000000","157 High Street","000001","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000" ,
"A","0101059","01","01","0520","JOHN R FOX","MADE UP","test","000000","","0000004.00","","01"," test"," Re ticked on Sunday 13th after CSV run  Unticked 11.10am Weds 16th Jan2013. Nigel has been advised. Didn't leave the web site.  29th Jan 2013 Stock level re-set to nill.  2 Feb Item gone from web site : Correct. JRF","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","",,"0000000.00","0000000.00","29/12/12","Central Stock","000000","157 High Street","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000","","000000" , 

Open in new window



so that csv code is a snippet from what i get from the stock company and when i run it the category_ids dont come out into the fixed CSV. But the category_ids do come out into the fixed CSV if i use the old truncated CSV code.
Not sure what to look for here.  I ran it with the new input:
http://www.laprbass.com/temp_helpchrisplz/

Nothing in error_log.  OK?
if i look at your hosted output by opening the fixedSERVER.cfg i can see that the problem has moved to the tax_class_id it should have taxable goods in it but whats happening is its moving all the columns over by one.

also some of the products dont have category ids.

if you run the old truncated csv through the script it will work perfect  i just dont know what the difference is.
Chris, it's probably as simple as a mismatch between the number of column headers and the number of columns in the data.  If I had a magic wand to fix it, I would.

What concerns me about tainted data like this is that it could be "bad" in a number of ways, and the process for creating it could be unpredictable.  So even if you get this one data set to work correctly, who knows whether the solution will be applicable to the next one?

We know for sure that the first 16 columns can be handled correctly.  But after that, it's not a question with an answer -- it's a data research project to identify the missing pieces and put them in place.
the old truncated source csv works fine and this csv has loads of broken bits.
the new csv that is not truncated looks completely fine but has these problems with the columns going one to the left.

so i am looking for a reason why the new csv thats ment to be perfectly formed.. is causing the script to create problems with the outputted columns.

If your saying its that it could be "bad" in a number of ways. Then give me a few tips on how it could be bad? please.
SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
its longer because the  csv has a comma in one of the descriptions.
Yeah, that's the sort of problem you run into with this kind of data.  You need a state engine to parse it.  I believe that fgetcsv() has such a state engine.  I don't have time to write a state engine for free.

If you have this CSV file in clear text (not ZIP, but just CSV format) and you can post the public-facing URL, I'll try reading the CSV file with PHP.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ok
christophersowerby.com/non truncated csv.CSV

talking about the code in the index.php here:
i found that the csv data is populating the array correctly but in the foreach ($out as &$cur) that processed the array i have:
 $cur = array('special_price' => $special_price) + $cur;
that puts the modified data back to the array at position 1.

some rows are getting put back to the array at different positions. so i am expecting that some rows are not getting processed by some of the if statements in my loop and are missing the correct time to be reinstated into the array.

i have narrowed it down to the if(!empty($reason)){ part of the code. around line 246.

if i uncomment everything from within the loop after this point. my array will have its positions correct for every row.

so the if statements are not catching the data correct?

its just weird because i dont get any of these issues using the old truncated CSV. Thats why i was sure it was a problem with the provided data.
correct we don't need to worry about the 310 columns. the data i need is only in 0 - 16
I tried to read from christophersowerby.com/non truncated csv.CSV and got a 500 Internal Server Error.  Could you please create a copy of the file that has no blanks in the file name, check it to see that it can be read by a browser, then post the fully qualified URL here?  Thanks.
omg. think i just make it work.

i replaced //$cur = array('category_ids' => $sub_category) + $cur;  
             
with: $cur['category_ids'] = $sub_category;

at 2 parts of the code.
category_ids are filled out for every products now.
new index.php:

<?php
// this script will remove the crap from the source csv and make it valid

///////////////////////////////////////////////////
// this is how we get the latest CSV file name from the directory.
///////////////////////////////////////////////////
//$dir = "./csv"; 
$dir = "./in";         
$pattern = '/\.(csv|CSV)$/'; // check only file with these ext.          
$newstamp = 0;            
$latestFile = "";

if ($handle = opendir($dir)) {               
       while (false !== ($fname = readdir($handle)))  {            
         // Eliminate current directory, parent directory            
         if (preg_match('/^\.{1,2}$/',$fname)) continue;            
         // Eliminate other pages not in pattern            
         if (! preg_match($pattern,$fname)) continue;            
         $timedat = filemtime("$dir/$fname");            
         if ($timedat > $newstamp) {
            $newstamp = $timedat;
            $latestFile = $fname;
          }
         }
        }
closedir ($handle);



///////////////////////////////////////////////////
// get the csv in an array so we can edit the array
///////////////////////////////////////////////////


error_reporting(E_ALL);

echo '<body><pre><p class="headingText" style="text-align:center;margin-top:7%;font-size:30px;">Please wait... loading CSV rows...</p><div class="hide">';
?>
<script src="https://code.jquery.com/jquery-latest.min.js"
        type="text/javascript"></script>
<script type="text/javascript">     
     $(".hide").css("display", "none");      
</script>
<?php


//$url = "csv/".$latestFile;
$url = "in/".$latestFile;
$fpr = fopen($url, 'r');
if (!$fpr) trigger_error("UNABLE TO READ $url", E_USER_ERROR);

// WITH THE FILE OPENED, READ THE FIRST RECORD
$top = fgetcsv($fpr);

// count($top) is the number of columns
$numcols = count($top);

//echo $numcols;
// DATA ANOMALY: ARRAY POSITION 9 APPEARS TO BE UNCAPTIONED AND UNUSED
$top[9] = 'empty';

// we cant have the duplicate heading names as it will break the array
// so we can append a number to the end of them.

$a = 1;
$b = 1;
$c = 1;
$d = 1;
$e = 1;
$f = 1;
$g = 1;

foreach ($top as &$fixHeadingName)
{

    
    if (strpos($fixHeadingName,'Description') !== false) {
       $fixHeadingName = "short_description";       
    }
    if (strpos($fixHeadingName,'Notepad') !== false) {
       $fixHeadingName = "description";       
    }
    if (strpos($fixHeadingName,'Action') !== false) {
       $fixHeadingName = "store";       
    }
    if (strpos($fixHeadingName,'Web Desc') !== false) {
       $fixHeadingName = "name";       
    }

    if (strpos($fixHeadingName,'Stock Number') !== false) {
       $fixHeadingName = "sku";       
    }
    if (strpos($fixHeadingName,'Quantity') !== false) {
       $fixHeadingName = "qty";       
    }
    // if heading contains Attr Type then add the number to it.
    // becasue we have more than one col named this! and it breaks the array..

    if (strpos($fixHeadingName,'Attr Type') !== false) {
       $fixHeadingName = $fixHeadingName.$a;
       $a++;
    }
    if (strpos($fixHeadingName,'Attr Desc') !== false) {
       $fixHeadingName = $fixHeadingName.$b;
       $b++;
    }
    if (strpos($fixHeadingName,'Attr Format') !== false) {
       $fixHeadingName = $fixHeadingName.$c;
       $c++;
    }
    if (strpos($fixHeadingName,'Attr Code') !== false) {
       $fixHeadingName = $fixHeadingName.$d;
       $d++;
    }
    if (strpos($fixHeadingName,'Attr Value') !== false) {
       $fixHeadingName = $fixHeadingName.$e;
       $e++;
    }
    if (strpos($fixHeadingName,'Avail Stock') !== false) {
       $fixHeadingName = $fixHeadingName.$f;
       $f++;
    }
    if (strpos($fixHeadingName,'Branch') !== false) {
       $fixHeadingName = $fixHeadingName.$g;
       $g++;
    }

    // make headings lowercase
    $fixHeadingName = mb_strtolower($fixHeadingName,'UTF-8');
}

// KEEP ONLY THE LEFTMOST POSITIONS / cols
 $top = array_slice($top,0,16);

// NOW READ THE OTHER RECORDS AND BUILD AN ARRAY OF ASSOCIATIVE ARRAYS
while (!feof($fpr))
{


    // READ THE ROW INTO AN ARRAY
    $cur = fgetcsv($fpr);


    // SKIP EMPTY ROWS
    if (!$cur) continue;

    // COMBINE KEYS AND VALUES
    $cur = array_slice($cur,0,16);
    $out[] = array_combine($top, $cur);
}



//var_dump($out);

// ACTIVATE THIS TO SEE THE ARRAYS
// print_r($out);   

// ACCESS THE DATA IN EACH ARRAY

echo "<h3>This script is reading the CSV and formatting the columns to be valid for magento.</h3>";
//echo "<div><p>once this script has all the column headings + cells displayed correctly we will<br> then write a script to save each row down to a new csv.<br> This CSV will then be ready for upload to the website<br> This will allow us to automate the process</p></div>";
$i = 0; // row counter
foreach ($out as &$cur)
{
    

    // do cat
    //attr type1, category

    $sub_category = $cur['category'];
    $supplier_name_long = $cur['supp name'];
    if(!$supplier_name_long) { $supplier_name_long = $cur['supp ref']; }
    if($sub_category == "1") { $cur = array('category_ids' => "40") + $cur; }
    elseif($sub_category == "2") { $cur = array('category_ids' => "41") + $cur; }
    elseif($sub_category == "3") { $cur = array('category_ids' => "47") + $cur; }
    elseif($sub_category == "4") { $cur = array('category_ids' => "38") + $cur; }
    elseif($sub_category == "5") { $cur = array('category_ids' => "39") + $cur; }
    elseif($sub_category == "6") { $cur = array('category_ids' => "42") + $cur; }
    elseif($sub_category == "7") { $cur = array('category_ids' => "43") + $cur; } 
    elseif($sub_category == "8") { $cur = array('category_ids' => "44") + $cur; }
    elseif($sub_category == "9") { $cur = array('category_ids' => "12") + $cur; } 
    elseif($sub_category == "10") { $cur = array('category_ids' => "18") + $cur; }
    elseif($sub_category == "11") { $cur = array('category_ids' => "46") + $cur; }
    elseif($sub_category == "18") { $cur = array('category_ids' => "17") + $cur; } 
    elseif($sub_category == "19") { $cur = array('category_ids' => "37") + $cur; }


    $sub_category = $cur['category_ids'];
    // now we create the product image url from the sku number
    // will look like this: /01-01-008.jpg
    $imageUrl = substr_replace($cur['sku'],"/",0,0);
    $imageUrl = substr_replace($imageUrl,"-",3,0);
    $imageUrl = substr_replace($imageUrl,"-",6,0);
    $imageUrl = substr_replace($imageUrl,".jpg",10,0);

    //create brand new headings
    // add new headings to the array
    // add the modifed varables to the array at pos 1

    $cur = array('thumbnail' => $imageUrl) + $cur;
    $cur = array('small_image' => $imageUrl) + $cur;
    $cur = array('image' => $imageUrl) + $cur;
    $cur = array('store_id' => "0") + $cur;

   $name = $cur['name'];
   // echo "<h4 style='margin: 20px 0 -11px 0'>This is row $i of the CSV</h4>"; echo "<br>";
    //echo strlen(trim($name)); 

    $filledIn = preg_match('/^ *$/', $name);
    if ( $filledIn > 0 && strlen(trim($name)) == 0) {  
        $name = "No name available.";
    }


    $description = $cur['description'];    
    $filledIn = preg_match('/^ *$/', $description);
    if ( $filledIn > 0 && strlen(trim($description)) == 0) {  
        $cur['description'] = "No description available.";
        //echo "string";
    }


    
    $cur = array('product_name' => $name) + $cur;
    $cur = array('name' => $name) + $cur;
 
    



    $price = $cur['price'];
    //$price = "0000000.20";
    //remove zeros from front of price 
    $price = ltrim($price, '0');

    // this will make sure the price has 0000 at the end of the price
    // and if the price is .20 then it will make it 0.2000
    // it seems this is how magento likes the price :/
    $price = number_format($price, 4, '.', '');
    $cur['price'] = $price;

    $reason = $cur['reason']; 
    
    $special_price = '';
                        if(!empty($reason)){

                            $sub_category = $cur['category_ids'];
                            
                            switch($reason){
                                case "25" :
                                    $new_cat = '48,49';
                                    $sub_category = "$sub_category".",".$new_cat;
                                    $take_off = (100 - 75) / 100;
                                    $total = $price * $take_off;
                                    $special_price = ($price - $total);
                                    break;
                                case "50" :
                                    $new_cat = '48,50';
                                    $sub_category = "$sub_category".",".$new_cat;
                                    $take_off = (100 - 50) / 100;
                                    $total = $price * $take_off;
                                    $special_price = ($price - $total);
                                    //if($code == '1402036') exit($special_price);
                                    break;
                                case "70" :
                                    $new_cat = '48,51';
                                    $sub_category = "$sub_category".",".$new_cat;
                                    $take_off = (100 - 30) / 100;
                                    $total = $price * $take_off;
                                    $special_price = ($price - $total);
                                    break;
                                case "10" :
                                    $new_cat = '48,52';
                                    $sub_category = "$sub_category".",".$new_cat;
                                    $take_off = (100 - 90) / 100;
                                    $total = $price * $take_off;
                                    $special_price = ($price - $total);
                                    break;
                                case "35" :
                                    $new_cat = '48,53';
                                    $sub_category = "$sub_category".",".$new_cat;
                                    $take_off = (100 - 65) / 100;
                                    $total = $price * $take_off;
                                    $special_price = ($price - $total);
                                    break;
                            }
                            
                            $cur['category_ids'] = $sub_category;
                            //$cur = array('category_ids' => $sub_category) + $cur;

                        }                       
                  

                        $cur = array('special_price' => $special_price) + $cur;

                       
            $attribute = $cur['attr type1'];
            if(!empty($attribute)){
                // if they have the following attribute then put the produts the the correct magento catagory
                if($attribute == 'GC'){                
                    $sub_category = "$sub_category".",43";                
                }
                switch($attribute){
                case 'SJ':                
                $sub_category = "$sub_category".",54,55";                  
                break;
                case 'LQ':               
                $sub_category = "$sub_category".",54,56";  
                break;
                case 'CW':                
                $sub_category = "$sub_category".",54,57";
                break;
                case 'PB':                
                $sub_category = "$sub_category".",54,58";
                break;
                case 'CB':                
                $sub_category = "$sub_category".",54,59";
                break;
                case 'RC':                
                $sub_category = "$sub_category".",54,60";
                break;
                case 'JF':                 
                $sub_category = "$sub_category".",54,61";
                break;
                case 'SO':                  
                $sub_category = "$sub_category".",54,62";
                break;
                case 'DH':                  
                $sub_category = "$sub_category".",54,63";
                break;
                case 'AA':                 
                $sub_category = "$sub_category".",54,64";
                break;
                case 'KK':                
                $sub_category = "$sub_category".",54,65";
                break;
                case 'UU':                 
                $sub_category = "$sub_category".",54,66";
                break;
                case 'ML':                 
                $sub_category = "$sub_category".",54,67";
                break;
                case 'BR':                  
                $sub_category = "$sub_category".",54,68";
                break;
                case 'CA':                  
                $sub_category = "$sub_category".",69,70";
                break;
                case 'CH':                 
                $sub_category = "$sub_category".",69,71";
                break;
                case 'CR':                  
                $sub_category = "$sub_category".",69,72";
                break;
                case 'DR':                  
                $sub_category = "$sub_category".",69,73";
                break;
                case 'FB':                  
                $sub_category = "$sub_category".",69,74";
                break;
                case 'F4':                 
                $sub_category = "$sub_category".",69,75";
                break;
                case 'IN':                  
                $sub_category = "$sub_category".",69,76";
                break;
                case 'NS':                  
                $sub_category = "$sub_category".",69,77";
                break;
                case 'PO':                  
                $sub_category = "$sub_category".",69,78";
                break;
                case 'TW':                 
                $sub_category = "$sub_category".",69,79";
                break;
                case 'TH':                 
                $sub_category = "$sub_category".",69,80";
                break;
                case 'TU':                  
                $sub_category = "$sub_category".",69,81";
                break;
                case 'UR':                 
                $sub_category = "$sub_category".",69,82";
                break;
                case 'TB':                  
                $sub_category = "$sub_category".",69,83";
                break;
              }
              //$cur = array('category_ids' => $sub_category) + $cur;  
              $cur['category_ids'] = $sub_category;
            }
           



// disable product if not in stock
$quantity = $cur['qty'];
if ($quantity > 0) {
  $cur = array('status' => "Enabled") + $cur;
} else {
  $cur = array('status' => "Disabled") + $cur;  
}

// add the other crap magento wants.                                             
$cur = array('websites' => "base") + $cur; 
$cur = array('attribute_set' => "Default") + $cur; 

$cur = array('type' => "simple") + $cur;
$cur = array('has_options' => "1") + $cur;
$cur = array('tax_class_id' => "Taxable Goods") + $cur;
$cur = array('visibility' => "Catalog, Search") + $cur;
$cur = array('enable_googlecheckout' => "Yes") + $cur;
$cur = array('is_recurring' => "") + $cur;
$cur = array('manufacturer' => $supplier_name_long) + $cur;
$cur = array('cost' => "") + $cur;
$cur = array('weight' => "") + $cur;        
$cur = array('url_key' => "") + $cur; 
$cur = array('gift_message_available' => "Use config") + $cur; 
$cur = array('meta_title' => "") + $cur; 
$cur = array('meta_description' => "") + $cur; 
$cur = array('custom_design' => "") + $cur; 
$cur = array('page_layout' => "No layout updates.") + $cur; 
$cur = array('options_container' => "Block after Info Column") + $cur; 
$cur = array('image_label' => "") + $cur; 
$cur = array('small_image_label' => "") + $cur; 
$cur = array('thumbnail_label' => "") + $cur; 
$cur = array('url_path' => "") + $cur; 
$cur = array('meta_keyword' => "") + $cur; 
$cur = array('custom_layout_update' => "") + $cur; 
$cur = array('news_from_date' => "") + $cur; 
$cur = array('news_to_date' => "") + $cur; 
$cur = array('special_from_date' => "") + $cur; 
$cur = array('special_to_date' => "") + $cur; 
$cur = array('custom_design_from' => "") + $cur; 
$cur = array('custom_design_to' => "") + $cur; 
$cur = array('min_qty' => "0") + $cur; 
$cur = array('use_config_min_qty' => "1") + $cur; 
$cur = array('is_qty_decimal' => "0") + $cur; 
$cur = array('backorders' => "0") + $cur;
$cur = array('use_config_backorders' => "1") + $cur;
$cur = array('min_sale_qty' => "1") + $cur;
$cur = array('use_config_min_sale_qty' => "1") + $cur;
$cur = array('max_sale_qty' => "0") + $cur;
$cur = array('use_config_max_sale_qty' => "1") + $cur;
$cur = array('is_in_stock' => "0") + $cur;
$cur = array('low_stock_date' => "") + $cur;
$cur = array('notify_stock_qty' => "0") + $cur;
$cur = array('use_config_notify_stock_qty' => "1") + $cur;
$cur = array('manage_stock' => "0") + $cur;
$cur = array('use_config_manage_stock' => "0") + $cur;
$cur = array('stock_status_changed_automatically' => "1") + $cur;
$cur = array('use_config_qty_increments' => "1") + $cur;
$cur = array('qty_increments' => "0") + $cur;
$cur = array('use_config_enable_qty_increments' => "1") + $cur;
$cur = array('enable_qty_increments' => "0") + $cur;
$cur = array('product_name' => "") + $cur;
$cur = array('product_type_id' => "Simple") + $cur;
$cur = array('product_status_changed' => "") + $cur;
$cur = array('product_changed_websites' => "") + $cur;










    $sku = $cur['sku'];
   // echo " and its sku is: ".$sku."<br><br>"; 
    $cur = array('sku' => $sku) + $cur;                         

    $cur = array('store' => "admin") + $cur;  



   
    $i++;
    echo "<h4 style='margin: 20px 0 -11px 0'>Row $i is in the array</h4>";

}

// echo "<br>This is the array before it gets output.<br>";
print_r($out);
  //  echo "//////////////////////////////////////////////////////////////////////////";

$i--;

$mod_date=date("F d Y H:i:s.", filemtime("in/".$latestFile));
echo "<p>Processed CSV with file name: </p><a href='./in/$latestFile'>$latestFile</a> <br><br>This file was uploaded on: $mod_date<br>";




// WRITE A CSV FILE FROM THE ARRAYS
$fpo = fopen('fixedSERVER.CSV', 'w');
if (!$fpo) trigger_error("UNABLE TO WRITE CSV", E_USER_ERROR);
$i = 0; // row counter


foreach ($out as &$cur)
{

    
    // remove bad cols:
    
    unset($cur['empty']); 
    unset($cur['category']); 
    unset($cur['menu']);
    unset($cur['sub menu']);
    unset($cur['supp code']);
    unset($cur['supp name']);
    unset($cur['supp ref']);
    unset($cur['reason']);
    unset($cur['attr type1']);

                            

    if ($i == 0) {      

       $cvsHeadings = array_keys($cur);  
       //print_r($cvsHeadings); 
       fputcsv($fpo, $cvsHeadings); // Write information to the file
       fputcsv($fpo, $cur); // first row will get missed out if we dont output it here
    } else {

      //testing...
      $testStockNumber = $cur['sku'];
      
      if ($testStockNumber == "0101059") { // the offeding row thats breaking
        $testCategory = $cur['category_ids'];
        echo "".$testStockNumber." my category_ids is: |".$testCategory."| but why does this not show in the exported CSV?<br>";
      }

        // now we have the headings in just add ech row
        fputcsv($fpo, $cur); // Write information to the file
    }

    $i++;
}
// ACTIVATE THIS TO SEE THE ARRAYS
//print_r($out);
echo "<br><h4>".$i." rows processed</h4>";
echo "your fixed CSV is ready for download:<br>";
?>
<a style="color:red;font-size:19px;line-height: 69px;" class="hide" href="./fixedSERVER.CSV">fixed.CSV</a>

</div>
</body>
<script type="text/javascript"> 

$(document).ready(function () {
  $('.hide').fadeIn(3000);   
  setTimeout(function () {
    $('.headingText').text('Done!');  
  }, 1700);
});        
     
</script>

Open in new window

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
my problem ended up not being a CSV data problem.

but as this question was titled: csv breaking.
There is some good posts here on how to test the data in a csv.
Thanks for your time ray.