www.webdeveloper.com
Results 1 to 2 of 2

Thread: get only first coulmn to concat with each second column rows from csv file using php

  1. #1
    Join Date
    Jan 2014
    Posts
    10

    Question get only first coulmn to concat with each second column rows from csv file using php



    Hello,

    I have the below code to fetch csv file data:

    PHP Code:
    <?php
    if ($_FILES["file"]["error"] > 0)
    {
       echo 
    "Error: " $_FILES["file"]["error"] . "<br>";

    echo 
    "No files...!!!!!";

    echo 
    "<script>alert('No files...!!!!!');window.location.href='upload_file.php';</script>";
    }
    else
    {
    $a=$_FILES["file"]["tmp_name"];
    $csv_file $a

    if ((
    $getfile fopen($csv_file"r")) !== FALSE) {
            
    $data fgetcsv($getfile1000",");
      while ((
    $data fgetcsv($getfile1000",")) !== FALSE) {
        
    //$num = count($data);
      //echo $num;
           //for ($c=0; $c < $num; $c++) {
               
    $result $data;
               
    $str implode(","$result);
               
    $slice explode(","$str);
           
               
    $col1 $slice[0];
               
    $col2 $slice[1];
               
    $col3 $slice[2];
               

           echo 
    $col1."".$col2."".$col3."<br/>";

    }
    }

    }

    ?>
    Now, thw above code prints all the dat from csv files but I want to print "all first coulmn rows to concat with each second column rows " .

    I know it is possible but I am stuck to use the logic "foreach" in the code above. can someone please help me out here ?

  2. #2
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,348
    When a file is uploaded to the temporary area in the server, your script should move the file to a location that is accessible from your web root.

    Move the file after checking it was uploaded
    /function.is-uploaded-file.php
    then
    /function.move-uploaded-file.php

    select the most appropriate read method for the file

    file_get_contents function.file-get-contents.php
    readfile /function.readfile.php
    CSV /function.fgetcsv.php
    etc.
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles