0

I have 3400 data and I want to insert all of my data into database. But, it seems some data are skipped during the process. How to make sure all data are inserted. Thank you.

Here is my code:

<?php  

include 'koneksi.php';
mysql_query("TRUNCATE token");

$komentar=mysql_query("SELECT * FROM dataset_komentar") or die(mysql_error());
$stopwords=mysql_query("SELECT * FROM stopwords") or die(mysql_error());

$index=0;

$arrSw=array();
while ($result1=mysql_fetch_assoc($stopwords)) {
    $arrSw[$index]=$result1['kata'];
    $index++;
}

if (mysql_num_rows($komentar)>0){
    while ($result2=mysql_fetch_assoc($komentar)) {
        $str2=$result2['komentar'];
        $newStr=preg_replace('/[^a-zA-Z]/', ' ', strtolower($str2));
        $newStr=str_replace("'", '', $newStr);

        $token=strtok($newStr, " ");
        $kata="";

        while ($token) {
            for ($i=0; $i<count($arrSw); $i++) { 
                if (trim($arrSw[$i])==$token) {
                    $token="";
                }
            }
            $kata.=$token." ";
            $token=strtok(" ");
            if (!empty($token)) {
                mysql_query("INSERT INTO token VALUES('','$token') ON DUPLICATE KEY UPDATE hasil_token=hasil_token")or die(mysql_error());  
            }
        }
    }
} else {
    echo "No data !";
}?> 
Al Foиce ѫ
  • 4,195
  • 12
  • 39
  • 49
brown26
  • 89
  • 1
  • 3
  • 10
  • if you want to make sure that all were successfull, use [`mysql_affected_rows()`](http://php.net/manual/en/function.mysql-affected-rows.php) – Funk Forty Niner Nov 13 '16 at 15:36
  • 5
    About 100 years ago, we stopped using this API. Join us. – Strawberry Nov 13 '16 at 15:38
  • Every time you use [the `mysql_`](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) database extension in new code **[a Kitten is strangled somewhere in the world](http://2.bp.blogspot.com/-zCT6jizimfI/UjJ5UTb_BeI/AAAAAAAACgg/AS6XCd6aNdg/s1600/luna_getting_strangled.jpg)** it is deprecated and has been for years and is gone for ever in PHP7. If you are just learning PHP, spend your energies learning the `PDO` or `mysqli` database extensions. [Start here](http://php.net/manual/en/book.pdo.php) – RiggsFolly Nov 13 '16 at 15:38

0 Answers0