News:

Tekforums.net - The improved home of Tekforums! :D

Main Menu

php/MySQL Question

Started by GroovyPigThing, April 10, 2006, 09:15:01 AM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

GroovyPigThing

I have an excel spreadsheet with about 500 rows that i want to insert into a MySQL table. Is there a quick and easy way to do it?

Cheers

Sweenster

There are definately programs that do it, like navicat, can also be done by php.

Never done it myself but just look around on google and you will find a method

Christopher Monkey

You could just write a small bit of code in excel


Function insert_to_MySQL()

Dim oApp as MySQL.Application
Dim oTab as oApp.Table
Dim iTemp as Integer

set oApp = New MySQL.Application
set oTab = oApp.Tables.Add("NewTableName")

iTemp = 1

Do While Not Range("a" & iTemp) = ""
    DoCmd.RunSQL("SELECT INTO " & oTab & " VALUES(" & Range("A" & iTemp & ")" & " & Range("B" & iTemp & ")" & " & Range("C" & iTemp & ")" & " & Range("D" & iTemp & ");")
    iTemp = iTemp + 1
Loop

End Function


The syntax for MySQL may be wrong in that.... ive not got it installed so couldnt reference it!

GroovyPigThing

cheers for that, Ive managed to do it now :)

M3ta7h3ad

Or... you could just export to CSV, and import using phpMyAdmin (pretty sure it can do that)

Christopher Monkey


GroovyPigThing

i only needed one column of data to go into a table so i just transposed the column into a row in excel and exported it to CSV and then just pasted it into a form i wrote that exploded the huge long string into an array and added everything from there.

not pretty but it was quick and since I only needed to do it once I decided I couldnt be bothered with a prettier way :p

thanks for your help though - might play with that sometime and see if I can make it work :)