Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Php report from mysql
Old 02-21-2011, 06:39 AM Php report from mysql
Average Talker

Posts: 22
Trades: 0
I have 4 csv i will go crazy i cant do it manualy any more

each csv have 4 colums

prefix| country | price 1 | price 2

The idea is to have 4 mysql tables for the 4 csv that i will have import them

and have a php script that when i will search for a prefix or country give me the results from the 4 tables


something like


table 1
prefix| country | price 1 | price 2

table 2
prefix| country | price 1 | price 2

table 3
prefix| country | price 1 | price 2

table 4
prefix| country | price 1 | price 2

Can anyone help me , i am desperate i create the db but dont know how to create the php script
nackgr is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-21-2011, 06:55 AM Re: Php report from mysql
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
From what I understand, what you need to do is convert each row in the CSV into an insert query.

PHP Code:
$raw_csv file_get_contents('path/to/file.csv');
$csv str_getcsv($raw_csv);

//remove this line if you don't need to drop the column titles
array_shift($csv);

//connect to the database
mysql_connect('localhost''username''password');
mysql_select_db('dbname');

$table 'table_name';
foreach(
$csv as $row)
{
     
$query "INSERT INTO $table (prefix, country, price_1, price_2) VALUES ('{$row[0]}', '{$row[1]}', '{$row[2]}', '{$row[3]}');";
     
mysql_query($query);
}

mysql_close(); 
I have not tested this script.

If this is not a one time conversion or if you're using very large files you may want to do a batch insert or dump the queries into a file, otherwise mysql_query should do fine.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by NullPointer; 02-21-2011 at 07:00 AM..
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 02-21-2011, 06:58 AM Re: Php report from mysql
Average Talker

Posts: 22
Trades: 0
tnx for ur reply

i have ready the db and the csvs are imported to tables i dont know how to make a script that i will have a search box and when i will write country

e.g Italy

Will give me 4 results for the 4 tables

Table A

Italy mpla mpla mpla

Table 2

Italy mpla mpla mpla

etc etc
nackgr is offline
Reply With Quote
View Public Profile
 
Old 02-21-2011, 07:03 AM Re: Php report from mysql
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
My mistake I completely misread your first post.

Why are you using 4 tables with identical schema? Is there a reason why you can't use one table? It might make more sense and be easier to manage a single table with an extra column to differentiate between whatever the distinguishing factor between the four is. It looks like most important part of writing your search script will be writing the SQL query.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by NullPointer; 02-21-2011 at 07:17 AM..
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Reply     « Reply to Php report from mysql
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.53184 seconds with 12 queries