0

i'have problem when using simple html dom

my question is..

i want grabbing content from other website

but when i'm insert to db he is duplicate data or content

and how there was not duplicate data or entry

this for my code

include "simple_html_dom.php";
$html = new simple_html_dom();
$html = file_get_html('http://example/');


$items = $html->find('div[class=thumb-box latest-entries],div[class=thumb-box latest-entries no-margin]');  
$nomor=1;
// loop into each li element
//echo"<h1>class margin</h1>";
foreach($items as $i => $post) {
    // get the img
    $img = $post->find('img', 0)->src;

    // get the post's url       
    $url = $post->find('a', 0)->href;

    // get the title
    $title = $post->find('h2[class=article-heading]a', 1)->plaintext;

    // another way to get the title
   // $title2 = $post->find('div[article-text]', 0)->plaintext;

    // get the description
    $desc = $post->find('p[class=article-text]', 0)->plaintext;

    //get date
    $date = $post->find('span[class=date]', 0)->plaintext;

    //get comment
    $comment = $post->find('span[class=comment]', 0)->plaintext;

    //get view
    $view = $post->find('span[class=view]', 0)->plaintext;

    // Print all

   if($title != "" && $url !="" && $img !="" && $desc !="" && $date !="" && $comment !="" && $view !="")
    {
   echo "<h1>$nomor</h1>
            Title   :$title<br>
           Image    :$img<br>
           Url      :$url<br>
           Description :$desc<br>
           Date     :$date<br>
           Comment  :$comment<br>
           View     :$view<br>";
           $gambar =$img; 
           $link   =$url;
    echo "<hr/>";
    }
    $nomor++;
$display=mysql_query("select * from homepage where title='$title' && url='$url' && image='$img'");
if(mysql_num_rows($display)>0)  
{
echo"<b style='color:red;'>title and url has Registered in database</b>";
}
else
{
    mysql_query("INSERT INTO homepage (title,image,url,description,date,comment,view)values('$title','$gambar','$link','$desc','$date','$comment','$view')")or die("".mysql_error());
}

}

1 Answer 1

1

Did you checked with phpmyadmin for the content? It may have been added to database, but your $display query might not work properly, so it will always have zero rows => is trying to add new entries to database when they are already added.

Sign up to request clarification or add additional context in comments.

2 Comments

Also, which is your primary key? Is it composed of multiple atributes?
ok thanks besciualex i have checked in phpmyadmin is add new and step first i'm grabbing success but when i'm gabbing step two he is to be duplicate entry in my db

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.