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

  • Home
  • SEARCH
  • 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 9030359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T07:28:15+00:00 2026-06-16T07:28:15+00:00

i have a function what separate my file’s content. Example file: 001;text1 002;text2 003;text3

  • 0

i have a function what separate my file’s content. Example file:

001;"text1"
002;"text2"
003;"text3"
999
001;"tekst11"

Sometimes some indexes have a few values:

120;"text2"
120;"text3"

My function:

function parseCSV($file) {
   $lines = file($file);
   $output = array();
   $i = -1;
   foreach($lines as $line) {
      $line = trim($line);
      if($line == "999") {
         $i++;
      } else {
         $ex = explode(";", $line, 2);
         $val = str_replace("\"", "", $ex[1]);
         //$dodaj = mysql_query("INSERT INTO `czynsz` (`$ex[$i]`) VALUES ('$val')");
         if(isset($output[$i][$ex[0]])) {         
            if(is_array($output[$i][$ex[0]])) {

               $output[$i][$ex[0]][] = $val;
            } else {
               $output[$i][$ex[0]] = array($output[$i][$ex[0]], $val);
            }
         } else {
            $output[$i][$ex[0]] = $val;
         }
         $dodaj = mysql_query("INSERT INTO `czynsz` (`$ex[$i]`) VALUES ('$val')");
      }
   }
   return $output;
}
$csvdata = parseCSV("woda.txt");


echo "<pre>\r\n";
print_r($csvdata);
echo "</pre>\r\n";

Above script makes me multi-level array tree and separate arrays from themselves by separator (999), because in my file are many arrays… When an index has many values – the script makes for him internal tree. For example:

Array
    (
    [0] => Array
        (
        [001] => 06-001-03-13
        [002] => 06447
        [003] => F
        ...
        [097] =>
        [120] => Array
            (
            [0] => text1
            [1] => text2
            )
        )
    [1] => Array
    ...

And there is my question:
I have a problem with save this mega array in my MySQL base. Every index in array have the same in data base. When the same index will have many values (ex. 120) it can be implode. Thank you with all my heart for any form of help… 🙁

  • 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-16T07:28:16+00:00Added an answer on June 16, 2026 at 7:28 am

    Create a MySQL Table:

    CREATE TABLE `czynsz` (
      `id` INT NOT NULL ,
      `value` VARCHAR( 255 ) NOT NULL
    ) ENGINE = InnoDB;
    
    ALTER TABLE `czynsz` ADD UNIQUE `unique` ( `id` ) 
    

    Then use the following php code to insert the data

    ini_set('error_reporting', E_ALL); // just for debugging remove later
    ini_set('display_erorrs', 1); // just for debugging remove later
    
    function parseCSV($file) {
        $lines = file($file);
        $output = array();
        $i = 0;
        foreach($lines as $line) {
            $line = trim($line);
            if($line == "999") {
               $i++;
               continue;
            }
    
            list($id, $val) = explode(";", $line, 2);
    
            $val = str_replace("\"", "", $val);
    
            $result = mysql_query("
                INSERT INTO `czynsz` (
                    id, 
                    `value`
                ) VALUES (
                    '$id',
                    '$val'
                ) ON DUPLICATE KEY UPDATE 
                    `value` = CONCAT(`value`, ', ', '$val')"
            );
            if(!$result) {
                die(mysql_error());
            }
            if(isset($output[$i][$id])) {
                if(is_array($output[$i][$id])) {
                    $output[$i][$id][] = $val;
                } else {
                    $output[$i][$id] = array($output[$i][$id], $val);
                }
            } else {
                $output[$i][$id] = $val;
            }
        }
       return $output;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have implemented below function in a separate .js script file which I load
I have a Javascript function in a separate jsp file: (used <jsp:include> for file
I have a function in a separate .js file called jQuery.loadjson.js . That being
I have a function in my separate js file called hello(). On my page
I have an IF statement that consists of two separate function calls passing values
I have a background worker which calls a function within a separate class. This
I have three separate table variables in my Function, 1 of them is not
I have this countdown script wrapped as an object located in a separate file
I have a class A which is in a separate file( sayfile1.cpp ) class
I have a function that updates a MySQL table from a CSV file. The

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.