PDA

View Full Version : Batch add to database


erockguide
10-29-03, 06:55 PM
Is there a way to add a ton of information to a database at once. For example, I have over 1000 names (not people) that I would like to put into my database. I have the names written in WOrd, and not in any particular order. I would like to just copy and paste them, and have the database be able to put each name in it's own column, so that I can order the names any way I want.

Is there a way to do this, or at least a way to add them without doing it manually. It would take a couple months to do it that way.

Thanks

HalfaBee
10-29-03, 10:54 PM
Save the document in txt format.
Upload to your server.
Then run a little script to add the names to table.
Something like this.



$data = file( 'names.txt' );

// connect to DB, you can do this part

foreach( $data as $name ) {
$name = trim( $name );
$sql = "INSERT into table_name SET col_name='$name'";
mysql_query( $sql );
}
// All done


HalfaBee