0
i'have 문제 항목을 중복간단한 HTML DOM MySQL의에서
내 질문은 ... 내가에 삽입있을 때 내가 다른 웹 사이트
컨텐츠를 잡는하지만 원하는
DB 그는 중복 데이터 나 콘텐츠
이며, 데이터 또는 항목 내 코드에 대한
이가 중복되지 않은 방법
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());
}
}
또한 기본 키는 무엇입니까? 여러 개의 속성으로 구성되어 있습니까? – besciualex
고마워 besciualex 내가 phpmyadmin에서 새 스크립트를 추가하고 첫 걸음을 내딛고 있지만 성공을 잡아 먹을 때면 나는 두 번째 단계를 깁니다. 내 데이터베이스에 중복 항목이 될 것입니다 – badruz
그게 당신을 위해 일해 주시면 답을 받아주십시오. 감사! – besciualex