Webmaster Forum


Go Back   Webmaster Forum > Web Development > Coding Forum

Coding Forum Problems with your code? Discuss coding issues, including JavaScript, PHP & MySQL, HTML & CSS, Flash & ActionScript, and more.


Reply
 
LinkBack Thread Tools Display Modes
Share |
  #1 (permalink)  
Old 04-28-2010, 10:52 AM
Incognito's Avatar
Junior Member
 
Join Date: 02-25-10
Location: Los Angeles, CA United States
Posts: 29
iTrader: 0 / 0%
Upload .csv to phpMyAdmin

has anybody had any particular experience with not getting this right the first time and then being able to upload it properly. I am having trouble uploading the script though it seems so simple...the fields don't fill in.

Thanks.
 
Reply With Quote
  #2 (permalink)  
Old 04-29-2010, 02:03 PM
Junior Member
 
Join Date: 04-29-10
Posts: 28
iTrader: 0 / 0%
Oh csv are a mad mess i have a script that will convert a csv to sql and then you would just run it as regular sql

Try taking this file and running it on your server :
Code:
<HTML> <HEAD> <TITLE>CSV to SQL convertor</TITLE> </HEAD> <BODY> <H2>CSV to SQL convertor</H2> <!-- Input form begin --> <FORM NAME="csv2sql" METHOD=POST ACTION="<? echo $PHP_SELF; ?>"> <INPUT TYPE="HIDDEN" NAME="ref" VALUE="csv2sql"> Insertion table: <BR> <INPUT CLASS="DEFAULT" TYPE="TEXT" NAME="table_name" VALUE="" SIZE=50> <BR><BR> CSV data: <BR> <TEXTAREA CLASS="DEFAULT" NAME="csv_data" ROWS=30 COLS=100></TEXTAREA> <BR><BR> <INPUT CLASS="DEFAULT" TYPE=SUBMIT VALUE=" Convert to SQL query "> </FORM> <!-- Input form end --> <?php // Parse incoming information if above form was posted if($_POST[ref] == "csv2sql") { echo "<h2>SQL Query Output:</h2>"; // Get information from form & prepare it for parsing $table_name = $_POST[table_name]; $csv_data = $_POST[csv_data]; $csv_array = explode("\n",$csv_data); $column_names = explode(";",$csv_array[0]); // Generate base query $base_query = "INSERT INTO $table_name ("; $first = true; foreach($column_names as $column_name) { if(!$first) $base_query .= ", "; $column_name = trim($column_name); $base_query .= "$column_name"; $first = false; } $base_query .= ") "; // Loop through all CSV data rows and generate separate // INSERT queries based on base_query + the row information $last_data_row = count($csv_array) - 1; for($counter = 1; $counter < $last_data_row; $counter++) { $value_query = "VALUES ("; $first = true; $data_row = explode(";",$csv_array[$counter]); $value_counter = 0; foreach($data_row as $data_value) { if(!$first) $value_query .= ", "; $data_value = trim($data_value); $value_query .= "$data_value"; $first = false; } $value_query .= ")"; // Combine generated queries to generate final query $query = $base_query .$value_query .";"; echo "$query <BR>"; } } ?>
 
Reply With Quote
  #3 (permalink)  
Old 04-29-2010, 08:56 PM
Incognito's Avatar
Junior Member
 
Join Date: 02-25-10
Location: Los Angeles, CA United States
Posts: 29
iTrader: 0 / 0%
thanks I'll try it out and let you know!
 
Reply With Quote
  #4 (permalink)  
Old 05-12-2010, 01:43 AM
Junior Member
 
Join Date: 04-15-10
Posts: 13
iTrader: 0 / 0%
Are you using the import function in PHPmyAdmin?
 
Reply With Quote
Go Back   Webmaster Forum > Web Development > Coding Forum

Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
phpMyAdmin SQL Text Too Small abajan Coding Forum 3 10-22-2009 09:05 AM
Accessing PHPMyadmin thewebhostingdir Web Hosting Forum 8 08-26-2009 01:02 AM


V7N Network
Get exposure! V7N I Love Photography V7N SEO Blog V7N Directory


All times are GMT -7. The time now is 09:55 AM.
Powered by vBulletin
Copyright © 2000-2013 Jelsoft Enterprises Limited.
Copyright © 2003 - 2013 Escalate Media LP




Search Engine Optimization by vBSEO 3.6.0 RC 2 ©2011, Crawlability, Inc.