Visit Our UNIX and Linux User Community

PHP read large string & split in multidimensional arrays & assign fieldnames & write into MYSQL

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting PHP read large string & split in multidimensional arrays & assign fieldnames & write into MYSQL
# 1  
Old 02-07-2010
Bug PHP read large string & split in multidimensional arrays & assign fieldnames & write into MYSQL

Hi, I hope the title does not scare people to look into this thread but it describes roughly what I'm trying to do. I need a solution in PHP.

I'm a programming beginner, so it might be that the approach to solve this, might be easier to solve with an other approach of someone else, so if you have an idea how to solve this the best way, I would be happy if someone could tell me.

I fetch a dataset and prepared it that it looks almost always the same.

The lenght (amount of rows) could be larger or shorter.
If there is a LOW somewhere in the dataset, a database field which was 'high' for the previous rows has to be 'low' from there on for the following rows, and high again for the next set of data to be fetched.

I have stored this fetched example data into a string, and it looks like this:

PHP Code:;analog6.008031845092773,'11.100.000''1.000.000'1110000010000000.93333334,€1,011007354,32,0,0,0,,BR,;analog6.008031845092773,'6.120.000''550.000'61200005500000.93333334,€1,011007354,32,0,0,0,,EX,;analog6.008031845092773,'11.100.000''1.000.000'1110000010000000.93333334,€1,011007354,32,0,0,0,,PH,LOW 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ;new analog4.548180103302002,'nicht ausreichend''110', -11100.46666667,€0,0550000,32,0,0,-1,-new,BR,;  0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ;new analog4.548180103302002,'nicht ausreichend''22', -1220.46666667,€0,0550000,32,0,0,-1,,EX,;  0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ;new analog4.548180103302002,'nicht ausreichend''46', -1460.46666667,€0,0550000,32,0,0,-1,,PH,
The Fields are delimeted by comma or semikolon, the dataset is delimeted by ,0 ;

The Plan is, to split the data into two variables first, so I get the High and Low data.

Then, for each variable, split its content into a multidimensional array containing the rows, delimitted by ',0;'

PHP Code:
explode(',0;'$low);;analog,  6.008031845092773,'11.100.000''1.000.000'111000001000000,  0.93333334,€1,011007354,32,0,0,0,,BR,;;;analog,  6.008031845092773,'6.120.000''550.000'6120000550000,  0.93333334,€1,011007354,32,0,0,0,,EX,
and then split again to the fields delimeted by Comma or Semkolon

PHP Code:



How would be the the correct syntax to read the array and assign each array field a database field and store it into a database. I have to do it row by row I think... and take care of high and low

PHP Code:
Field 'type' ==> 'high'

0.0 => 'Jan'
0.0 => 'Feb'
0.0 => 'March'
0, => 'Field xx'

EX => 'Field xy'
=> 'Field zz' 
Any ideas about this are welcome Smilie

Previous Thread | Next Thread
Test Your Knowledge in Computers #286
Difficulty: Easy
AIX Version 1 was introduced in 1986 for the IBM RT PC workstation, was based on HP-UX.
True or False?

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

SFTP Shell Script Get & Delete && Upload & Delete

Hi All, Do you have any sample script, - auto get file from SFTP remote server and delete file in remove server after downloaded. - only download specify filename - auto upload file from local to SFTP remote server and delete local folder file after uploaded - only upload specify filename ... (3 Replies)
Discussion started by: weesiong
3 Replies

2. Shell Programming and Scripting

Read input while another command is running &&

This script runs tshark, then displays the output. I want to read a keypress at all times throughout this script, especially during the 10 seconds that tshark is running. This code however, only takes input before tshark runs. #!/bin/bash main() { while (( "1" == "1" )) ; do keypress &&... (3 Replies)
Discussion started by: Kiah07
3 Replies

3. Shell Programming and Scripting

Using Grep & find & while read line in a script

Hello people! I would like to create one script following this stage I have one directory with 100 files File001 File002 ... File100 (This is the format of content of the 100 files) 2012/03/10 12:56:50:221875936 1292800448912 12345 0x00 0x04 0 then I have one... (0 Replies)
Discussion started by: Abv_mx81
0 Replies

4. Shell Programming and Scripting

How to write If statement using && and operator in Unix

Hi What is the syntax for if statement using && and || operator? if && ] || here its giving me an error to this if statement any suggestion?? (2 Replies)
Discussion started by: Avi
2 Replies

5. Shell Programming and Scripting

Find & Replace string in multiple files & folders using perl

find . -type f -name "*.sql" -print|xargs perl -i -pe 's/pattern/replaced/g' this is simple logic to find and replace in multiple files & folders Hope this helps. Thanks Zaheer (0 Replies)
Discussion started by: Zaheer.mic
0 Replies

6. Shell Programming and Scripting

How do I search first&second string & copy all content between them to other file?

Hi All, How do I search first string & second string and copy all content between them from one file to another file? Please help me.. Thanks In Advance. Regards, Pankaj (12 Replies)
Discussion started by: pankajp
12 Replies

7. Programming

Problem with read & write

Hello mates: I met problem with using read() & write(). I m trying to use read twice on client first time is the size of buffer, 2nd time is the buffer. I think I have to, coz I dnot know file size. So, I write twice on server as well -- 1st, filesize; 2nd, buffer. The problem is, sometimes,... (11 Replies)
Discussion started by: EltonSky
11 Replies

8. UNIX for Dummies Questions & Answers

PHP & Apache & MySQL install how-to ?

how do i install php & mysql with apache on suse linux ??? apache was installed and configured when i installed linux. all its files are in different folders. e.g http files in usr/local/httpd/htdocs/ and its configs are in etc/httpd/ so how do i install php and get it to work with apache and... (4 Replies)
Discussion started by: perleo
4 Replies

9. Programming

read, write & STDOUT_FILENO....

hi guys, I'have a question 4 u. Why this code give me the right output (an integer on the stdout): read(fd,&mpid,sizeof(pid_t)); printf("%d\n",mpid); Instead this code give me only a blank line: read(fd,&mpid,sizeof(pid_t)); write(STDOUT_FILENO,&mpid,sizeof(pid_t)); ... (2 Replies)
Discussion started by: M3xican
2 Replies

Featured Tech Videos