Sign Up

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

Have an account? Sign In

Have an account? Sign In Now

Sign In

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

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

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

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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

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

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

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

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

Mobile menu

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:43:43+00:00 2026-06-05T09:43:43+00:00

I have this code : <?php $handle = fopen(GeneratePicklist.csv, r); $data = fgetcsv($handle, 5000,

  • 0

I have this code :

<?php
   $handle = fopen("GeneratePicklist.csv", "r");
   $data = fgetcsv($handle, 5000, ",");
?>

Which opens up a php file and converts it into a php array. Then I will list out the array contents and display them into a formatted page. I have this code and it’s working.

<?php
    echo "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
        <tr>
            <td class=\"dataHeader\" width=\"100\">Mat.Loc.</td>
            <td class=\"dataHeader\" width=\"20\">Qty</td>
            <td class=\"dataHeader\">Description</td>
            <td class=\"dataHeader\" width=\"150\">Part Number</td>
            <td class=\"dataHeader\" width=\"30\">Multiplier</td>
            <td class=\"dataHeader\" width=\"80\">Total Qty</td>
        </tr>
";
$locatePartNoString = array_search("Part Number",$data);
$arrayStart = $locatePartNoString-1;
end($data);
$lastField = key($data);
$counter = ($lastField - $arrayStart);
$arrayBegin = $locatePartNoString+6;
while($counter>0) {
    echo "
        <tr>
            <td class=\"centered\"><span class=\"title\">*".$data[$arrayBegin+4]."*</span><br>".$data[$arrayBegin+4]."</td>
            <td id=\"qty".$counter."\" class=\"centered\">".$data[$arrayBegin+1]."</td>
            <td>".$data[$arrayBegin+2]."</td>
            <td class=\"centered\">".$data[$arrayBegin]."</td>
            <td class=\"centered\"><input type=\"text\" id=\"multiplier".$counter."\" name=\"multiplier".$counter."\" value=\"1\" size=\"3\" style=\"border:1px dotted #CCC;\"></td>
            <td class=\"centered\"><input type=\"text\" id=\"total".$counter."\" name=\"total".$counter."\" value=\"1\" size=\"3\" style=\"border:1px dotted #CCC;\"></td>
        </tr>

    ";
    $counter--;
}
echo "</table>";
?>

What I am trying to do is the traverse through the CSV file and select certain data only within the coverage of $arrayBegin variable and the last part of my CSV data. I have done the first line and its working good but I do not know how to increment so my pointer moves to the next line of the CSV file and do the same formula as my first line of data.

Here’s a sample of the CSV content, 7 fields:

ÊÊ,Part Number,Qty,Description,BB Type,Material Location,Serial Number
ÊÊ,013224-001,1,"PCA,DDR2-800,MINIDIMM MOD256MBx 40",BOM,ASSY,ID121608ZS
ÊÊ,122657-00A,1,SOFTWARE TEST (US M3 CTO),BOM,ASSY,
ÊÊ,376383-002,8,"ASSY, BLANK,SFF",BOM,ASSY,
ÊÊ,458943-003,1,"CA ASSY, SFP BATTERY, 15 POS, 28AWG, 24",BOM,ASSY,
ÊÊ,460499-001,1,"ASSY, 4/V650HT BATTERY CHARGER MODULE",BOM,ASSY,
ÊÊ,499256-001,2,"ASSY, BLANK,MEDIA BAY,ML350G6",BOM,ASSY,
ÊÊ,500203-061,2,"DIMM,4GB PC3-10600R,256Mx4,RoHS",BOM,ASSY,RAKWF8DXV2Q100

I just need to select certain data from each line and then move on to the next line. How do i traverse to the next line using my while loop? Thank you for your future responses.

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

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T09:43:46+00:00Added an answer on June 5, 2026 at 9:43 am

    This is typically how you go through a CSV file, starting with what you have already:

    $handle = fopen("GeneratePicklist.csv", "r");
    $firstRow = fgetcsv($handle, 5000, ",");
    $partNumberPosition = array_search("Part Number", $firstRow, true);
    

    At this point you have read the first line, which normally contains the field names. You have also determined at which column the ‘Part Number’ is at.

    And to fetch the rest:

    // the function `fgetcsv()` will return `false` when the end-of-file is reached
    while (false !== ($row = fgetcsv($handle, 5000))) {
        // we have read a(nother) row of data
        // if you're not interested in the columns before the 'Part Number'
        // you can slice them off
        $row = array_slice($row, $partNumberPosition);
        // at this point, $row contains:
        // 0 => the part number
        // 1 => the quantity
        // etc...
    }
    // we're done, close the file
    fclose($handle);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this php code $filename = verbs.php; // http://alylores.x10.mx/vega/verbs2.php $handle = fopen($filename, r);
I have this code in PHP writing views to a text-file and just increasing
I have this code in PHP. It connects to the DB fine, but pops
I have this php code $jsonArray = array(); $sql = SELECT ID,CLIENT FROM PLD_SERVERS;
I have this PHP code in a loop for every post on the admin
i have this php code and keep on getting errors upon fixing each error.
i have this PHP code, and a DataBase with Question, answer1, answer2, Question_id well,
I have this code in userpage.php: <script langauge=JavaScript><!-- function newWindow(fileName,windowName) { msgWindow=window.open(fileName,windowName); } //--></script>
For eg, I have this code for my PHP calendar events application. /**MySQL code
I have this code in my index.php. In Mozilla its ok. But in Ie

Explore

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

Footer

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

Insert/edit link

Enter the destination URL

Or link to existing content

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