I am using the latest phpmyadmin. I have a database and within it is a whole bunch of tables. I want to load a semicolon delimited text file but it doesn't seem to work. Here is the sample of my text file where 55 is the field id. Field title is the country name and the last is the ordering of my countries.

55;Portugal;178
55;Puerto Rico;179
55;Qatar;180
55;Reunion;181
55;Romania;182
55;Russia;183

All i am trying to do is populate the country list so I dont have to enter it manually. Is there any other way of doing this? Please help!

Thank you so much

Recommended Answers

All 3 Replies

use explode function to separate them...
see this...

if my post is not reach your requirement...please ignore this...

You might have to debug this a little but not much. This is how I would do it:

<?php
$data = "55;Portugal;178
55;Puerto Rico;179
55;Qatar;180
55;Reunion;181
55;Romania;182
55;Russia;183";

$queries = array();
foreach(explode("\n", $data) as $row)
{
    $line = "insert into tablename(fieldid, countryname, order) values(";
    foreach(explode(";", $row) as $col)
    {
        $line .= "'" . $col . "', ";
    }
    $queries[] = substr($line, 0, -2) . ");";
}

mysql_query("begin");
$commit = "commit";
$error = "";
$counter = 1;
foreach($queries as $query)
{
    if($commit == "commit") 
    {
        if(!mysql_query($query))
        {
            $error = "error in query " . $counter . ":" . mysql_error();
            $commit = "rollback";
        }
        $counter++;
    }
}
if($commit == "rollback")
{
    echo "transaction rolled back<br />" . $error;
}
mysql_query($commit);
?>

Thanks for inputs. still playing with it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.