[thelist] merging a dictionary to sql table

k.voronin at e3internet.com k.voronin at e3internet.com
Wed Nov 16 02:36:23 CST 2005


Hi, Alex

>im trying to merge one dictionary with another already in a couple of
>columns of a dictionary table. heres my code. its not really working -
>no words get inputted to the dictionary any ideas appreciated

First of all,

It's interesting what is the structure of the dictionary file?
("ENGLDICT.TXT")

Probably better use another function file();

This function creates the array from the file with lines.

$linesarray = file("ENGLDICT.TXT")

And the next question:

Do you have this file "ENGLDICT.TXT" in the same directory? (case-sensitive)

Try check if file open or not.

><?
>$time_start = microtime(true);
>include("database/connect-dictionary.php");
>$handle = fopen("ENGLDICT.TXT", "r");
>$counter=0;
>if ($handle) {
echo "file opened!";
>    while (!feof($handle)) {
>        $buffer = trim(fgets($handle, 4096));
>        $query_string = "SELECT word FROM word_list WHERE word =
> >'$buffer'";
>
>        $result = mysql_query ($query_string);// or die("not
> working1");
>
>        if(!$result){  // this might be a bad way to do it
>            $query = "INSERT into word_list(word) VALUES ('$buffer')";
>            mysql_query($query);
>            $counter++;
>        }
>    }
>fclose($handle);
>}
>mysql_close($link);
>$time_end = microtime(true);
>$time = $time_end - $time_start;
>echo "words added".$counter;
>echo $time;
>?>

Hope this helps,

Kirill,

E3internet, web-developer




More information about the thelist mailing list