1つの提案または状況に対処できる方法が欲しい
ウェブサイトをクロールして、近くの映画館で上映中の映画を入手するモジュールを使用しています。私はそのために2つのテーブルを持っています1)1つは映画用で、もう1つは最初に映画テーブルに挿入された映画を参照する映画館用です。
今のところ、毎朝 cron ジョブにファイルを設定しています。したがって、私のコードでは、最初に両方のテーブルのすべてのデータを削除し、新しいデータを挿入します。しかし、これによって、私は通常、その特定の映画についてエンド ユーザーによって与えられたすべての評価スコアを失います。
この状況を克服するために、私はいくつかの解決策を考えました
新しいクエリを作成しました
INSERT INTO jos_movie (movie_name, language, cast,movie_release,director,rating,rating_count,movie_ids)
SELECT * FROM (SELECT 'test','null','yahoo','Dec 21, 2012','himmat',250,230,'43677') AS tmp
WHERE NOT EXISTS (
SELECT movie_name FROM jos_movie WHERE movie_name = 'test')
同様に、シネマテーブルにも同じアプローチを作成しました。
これにより、テーブル内のムービーがチェックされ、上書きされなくなります。しかし、このアプローチにはいくつかの問題があります。映画館の所有者がその特定の映画の番組を削除した場合 (例: 'test' )。次に、上記のクエリでは、それを削除しません。そこに残ります。
この問題の適切な件名を考えることができないため、私の件名で申し訳ありません。
では、既存のムービーがテーブルにある場合は更新されず、スクリプトのクロール結果配列にない場合は削除されるように、どうすれば結果を達成できますか。
ここに私のテーブルの結果があります
これは映画テーブルの結果です
シネマテーブルです
ここに私が同じために使用しているコードがあります。
$con=mysql_connect('localhost','test','test');
mysql_select_db('test',$con);
// Use cURL to get the RSS feed into a PHP string variable.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'myrsslink.xml');
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$xml = curl_exec($ch);
curl_close($ch);
$arrData = array();
// Create an array of item elements from the XML feed.
$news_items = element_set('item', $xml);
$del_movie = "delete from jos_movie";
mysql_query($del_movie);
$del_cinema = "delete from jos_cinema";
mysql_query($del_cinema);
foreach($news_items as $item) {
$title = value_in('title', $item);
$url = value_in('link', $item);
$cast = value_in('description', $item);
//curl_setopt($ch, CURLOPT_URL,$url);
//curl_setopt($ch, CURLOPT_HEADER, false);
//curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//$html = curl_exec($ch);
$arrTitle = explode('-',$title);
$html = file_get_html($url);
$htmlShowTime = '';
// find all span tags with class=gb1 moviTimes moviTmngBox
foreach($html->find('ul[style=line-height:2em;]') as $e)
$htmlShowTime = $e->plaintext;
$movie_name = $arrTitle[0];
$apiKey = '30f44b6ef9472d414e50d2acaa058b60';
$url = sprintf('http://api.themoviedb.org/2.1/Movie.search/en/xml/%s/"%s"',$apiKey,rawurlencode(trim($movie_name)));
//$xml = simplexml_load_file("http://api.themoviedb.org/2.1/Movie.search/en/xml/accd3ddbbae37c0315fb5c8e19b815a5/"$movie_name"");
$xml = simplexml_load_file($url);
$movies = $xml->movies->movie;
foreach ($movies as $movie){
$arrMovie_id = $movie->id;
}
$arrStr = explode(':',$htmlShowTime);
$release = substr($arrStr[3],0,strlen($arrStr[3])-8);
$director = substr($arrStr[5],0,strlen($arrStr[5])-11);
$sql_movie = "insert into jos_movie(movie_name,language,cast,movie_release,director,rating,rating_count,movie_ids)values('$movie_name','null','$cast','$release','$director',250,230,'$arrMovie_id')";
//echo $sql.'<br>';
// echo $sql_movie;
mysql_query($sql_movie);
$sqlCount = 'select max(id) from jos_movie' or die("cannot select DB");
$data = mysql_query($sqlCount);
echo $data;
print_r($data);
$result = mysql_fetch_array($data);
$id = $result[0];
echo '<br>'.$id.'<br>';
//$id = mysql_insert_id();
//echo $id;
// find all span tags with class=gb1
foreach($html->find('div.moviTmngBox') as $e){
$tagTitle = $e->find('a',0);
$tagTime = $e->find('div.moviTimes',0);
$name = $tagTitle->title;
$time = $tagTime->innertext;
$trimName = '';
$temName = strtolower(str_replace(' ','',$name));
if(strpos($temName,'indraaudi1') !== false)
$trimName = 'Indra Audi 1' and $cinemaId = '1' and $long='32.726602' and $lat='74.857026';
elseif(strpos($temName,'indraaudi2') !== false)
$trimName = 'Indra Audi 2' and $cinemaId = '2'and $long='32.726602' and $lat='74.857026';
elseif(strpos($temName,'indraaudi3') !== false)
$trimName = 'Indra Audi 3'and $cinemaId = '3' and $long='32.726602' and $lat='74.857026';
elseif(strpos($temName,'apsra') !== false)
$trimName = 'Apsra' and $cinemaId = '4' and $long='32.700314' and $lat='74.858023';
else{
$trimName = trim(substr($name,18,strlen($name))) and $cinemaId = '5' and $long='32.7300' and $lat='74.8700' ;
}
//echo $tagTime->innertext.'<br/>';
$sql = "insert into jos_cinema(cinema_name,show_time,movie_id,cinemaId,logitude,latitude)values('$trimName','$time',$id,$cinemaId,$long,$lat)";
//echo $sql.'<br/>';
mysql_query($sql);
//$arrTem = array($tagTitle->title,$tagTime->innertext);
}
}//end rss feed loop
?>
映画のレーティングのデフォルト値を挿入していることに注意してください。
ありがとう