473,765 Members | 2,059 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to parse this,and input in mysql ?!

10 New Member
Hello all!
This might be simple,but im having some problems in parsing the php code, can someone help?
i have a text file with this (for example):
--------------------------------------------------------------------
blitzztriger [****] - time : 1


hello - ( 47) 52 40
30,000 (+600) 50% 20,000 (+400) 50%

hello2 - ( 48) 102 40
35,000 (+650) 100% 50,000 (+200) 90%
--------------------------------------------------------------------
the ideia is to :
"name" --->column 1(line1)the dump will be:blitzztriger
"hello"--->column 2(line1) the dump will be:hello (hello its a name)
"( 47)"--->column 3 (line1)the dump will be:47
"( 52)"--->column 4 (line1)the dump will be:52
"30,000"--->comumn 5(line1)the dump will be: 30000 (number)
"(+600)"--->column 6(line1)the dump will be : 600
"50%"------>colum 7(line1) the dump will be: 50
and so on...

"name" --->column 1(line2)the dump will be:blitzztriger
"hello2"-->column 2(line2) the dump will be:hello2 (hello2 its a name)
"( 48)"--->column 3 (line2)the dump will be:48
"(102)"--->column 4 (line2)the dump will be:102
"35,000"--->comumn 5(line2)the dump will be: 35000 (number)
"(+650)"--->column 6(line2)the dump will be : 650
"100%"----->colum 7(line2) the dump will be: 100
and so on...

then the dumped values should enter mysql DB.
i already tried millions of things but no way!! going mad... :(
thanks in advance
Jul 17 '07 #1
6 1635
blitzztriger
10 New Member
hum, if its difficult, can someone show me just one example?!
Jul 17 '07 #2
adamalton
93 New Member
I don't quite understand what it is that you're doing, but i can give a basic example of how to put stuff into a mysql database.

Once you've created the database with all of the columns that you want (ask if you want to know how to do that, there are various ways).

get your php script to connect to your database:
[PHP]$link=mysql_con nect("localhost " , "username" , "password") ;
mysql_select_db ("name_of_your_ database" , $link);[/PHP]

Create a query to insert stuff into your database:
[PHP]$query="INSERT INTO name_of_your_ta ble (name_of_column 1 , name_of_column2 , etc) VALUES ('value_to_go_i n_col_1' , 'value_4_col2' , 'etc')";[/PHP]
Then execute the query:
[PHP]mysql_query($qu ery);
if(mysql_error( ))
{
print "Oh, shit!<br>";
print mysql_error();
}
else
print "The stuff was put into the database.<br> Woo!!";[/PHP]

So you'd need to do that for each of the lines (ie records) that you want to add to the db.

I'm sure there's a different quicker method for adding lots of records at once, but this'll get you started.
Jul 17 '07 #3
blitzztriger
10 New Member
Thanks a lot , that part i already understood. :)
Now for a better comprehension of what i want to do , heres the table :

name id pieces (A) (pieces (b) working pieces (A) production (A)
blitzztriger 47 52 40 30000 600
blitzztriger 48 102 40 35000 650

and so on...

From a .txt file like this:
blitzztriger [****] - time : 1


hello - ( 47) 52 40
30,000 (+600) 50% 20,000 (+400) 50%

hello2 - ( 48) 102 40
35,000 (+650) 100% 50,000 (+200) 90%

I know that i must regex that file..and thats the problem...or should i put it in array´s and then connect it to the db?
even with the correct regex code, where should i put it to send to the db btw?, in here?
$query="INSERT INTO name_of_your_ta ble (name_of_column 1 , name_of_column2 , etc) VALUES ('value_to_go_i n_col_1' , 'value_4_col2' , 'etc')";
value_to_go_in_ col_1 = regex code ?
Jul 17 '07 #4
adamalton
93 New Member
I still don't understand!! Are you trying to split your text file into all of the separate items using regular expressions, and then put all of those items into the db?
Jul 17 '07 #5
blitzztriger
10 New Member
yes!! thats it!! :D
heres some regex for this part:
30,000 (+600) 50% 20,000 (+400) 50% 1,000 (+60) 50% 0 (+30) 50% 20,000

regex: ([\d,]+) \(\+([\d,]+)\) (\d+)% ([\d,]+) \(\+([\d,]+)\) (\d+)% ([\d,]+) \(\+([\d,]+)\) (\d+)% ([\d,]+) \(\+([\d,]+)\) (\d+)%
Jul 18 '07 #6
adamalton
93 New Member
I'm not hot on regular expressions, but my approach would be something like this:

Use fopen() or something to open the text file and stick the contents of it into a variable, $text.

Then something like this:
[PHP]while(preg_matc h("/hello/",$text))//while there is still at least one more record to do
{
list($junk,$tex t) = preg_split("/hello/",$text); //cut off stuff up to (and including) "hello"
list($junk,$tex t) = preg_split("/(/",$text); //cut stuff off up to the bracket (
list($value1,$t ext) = preg_split("/)/",$text); //so $value1 now contains the number that was between the brackets ()
list($junk,$tex t) = preg_split("/ /",$text);//cut off the space that comes after the closing bracket
list($value2,$t ext) = preg_split("/ /",$text); //$value2 now contains the number that comes before the next space (52 in the first one)
//just keep going through the bits until you've got all of the values into $variables.
//then add the dogs to the database:
$query="INSERT INTO table (column1,column 2,column3,etc) VALUES ('". $value1 ."','". $value2 ."','". $value3 ."','". $etc ."')";
mysql_query($qu ery);
}[/PHP]
I hope that helps
Jul 18 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

3
2866
by: Rob | last post by:
It's been driving me crazy...why is this returning a parse error? It says the error is on the last line, I thought I was following the syntax.... <?php $link = mysql_connect("localhost"); if(! $link) die("Could not connect to MySQL"); $database = "PC_Store";
3
2931
by: josh dismukes | last post by:
/// here is the code i'm getting a parse error on the last line of the code which /// is </html> any help will be much appreciated. <?php session_start ();
3
15063
by: Marten van Urk | last post by:
I got the following error in my page Parse error: parse error, unexpected T_ELSE in line 25 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Club</title> </head> <style type="text/css">
0
4245
by: Robert Mazur | last post by:
MySQL 5.0 alpha (binary install) on Solaris 9 -or- RedHat 8.0 mysql-connector-java-3.0.8-stable ----------------------- Is there something different going on with JDBC and the alpha version of MySQL 5.0? When trying to connect I am getting: ** BEGIN NESTED EXCEPTION **
4
3301
by: Peter Proost | last post by:
Hi group, it's been a long time since the last time I've been here but I have a question. I'm working with timespan.parse for calculating a duration, I have to add strings which are in the following format 15:36:12 ==Hours, minutes, seconds but sometimes there is a string like 55:26:32 ==which is correct cause the production machine was busy for 55 hours, but the timespan.parse crashes on this value because it expects 2.7:26:32. I've...
2
3089
by: martha70 | last post by:
I’m running PHP MySQL (zen-cart) I’m looking for info on CSV files with data sets and how I can import these into MySQL. I found a number of topics involving simple CSV files and I tried a number of programs designed to do this but none addressing data sets and export to multiple tables (three in my case) within a MySQL database. My CSV input text file (see example below) is comprised of lines related to one-another according to their line...
3
1928
by: deerhide | last post by:
Hi, I was updating my website, well trying to... and I somehow messed it up. I didnt build it, I bought it so I don't know alot about programming. I receive these errors when going to minbiketrader.com : Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /home/content/m/i/n/minibiketrader/html/index.php on line 2 Parse error: parse error, unexpected T_REQUIRE_ONCE in /home/content/m/i/n/minibiketrader/html/index.php on line...
6
10095
by: momogi | last post by:
I' making an database application. In one form (Input data Form), I need to fill the text field with the reference number automatically. This number must be start with date of today. For the example, 2007092401. And the text field must be filled with the largest number in database (the largest of that day). Firstly, the form will check if there's a number start with today's date. If it's not NULL, the form takes the biggest one. But if it...
9
3097
by: Gilles Ganault | last post by:
Hello I googled for samples, but I'd like to make sure there's no simpler way to parse tab-separated data read from a web page, before I can save them into a database: <?php $input = file_get_contents ("http://server/data.php"); //item1<TAB>item2<CRLF>
7
2592
by: lancewassing | last post by:
I'm hoping this question is simple. I am trying to create a login script for my already in place client manage using php. I have created a text file filled with usernames and passwords delimited by the "/" character. The file looks like this: lance/wassi norm /wassi amand/yandt aaron/willi miche/young i have an html form which uses the following code to post the userinput... this part works fine:
0
9399
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10007
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9835
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8832
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7379
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5276
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3924
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.