php - Not able to insert data in new column -
i have working code inserts data correctly now. trying add new column of movie_id in that. trying fetch movie id value xml , looping movie title data inserted in not correct. movie_name
object has 3-4 movies names. trying add movie id that.
$movie_name = $arrtitle[0]; $xml = simplexml_load_file("http://api.themoviedb.org/2.1/movie.search/en/xml/myapi/$movie_name"); foreach($xml->movies->movie $movies){ $arrmovie_id= $movies->id; } $movie_ids= $arrmovie_id[0]; $arrstr = explode(':',$htmlshowtime); $release = substr($arrstr[3],0,strlen($arrstr[3])-8); $director = substr($arrstr[5],0,strlen($arrstr[5])-11); $sql_movie = "insert jos_movie(movie_name,language,cast,movie_release,director,rating,rating_count,movie_ids)values('$movie_name','null','$cast','$release','$director',250,230,'$movie_ids')";
here full working code
<?php // include handy xml data extraction functions. include 'xml_regex.php'; include 'simple_html_dom.php'; $con = mysql_connect('localhost','test','test'); mysql_select_db('test',$con); // use curl rss feed php string variable. $ch = curl_init(); curl_setopt($ch, curlopt_url,'mytest.xml'); curl_setopt($ch, curlopt_header, false); curl_setopt($ch, curlopt_returntransfer, true); $xml = curl_exec($ch); curl_close($ch); $arrdata = array(); // create array of item elements xml feed. $news_items = element_set('item', $xml); $del_movie = "delete jos_movie"; mysql_query($del_movie); $del_cinema = "delete jos_cinema"; mysql_query($del_cinema); foreach($news_items $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 span tags class=gb1 movitimes movitmngbox foreach($html->find('ul[style=line-height:2em;]') $e) $htmlshowtime = $e->plaintext; $movie_name = $arrtitle[0]; $arrstr = explode(':',$htmlshowtime); $release = substr($arrstr[3],0,strlen($arrstr[3])-8); $director = substr($arrstr[5],0,strlen($arrstr[5])-11); $sql_movie = "insert jos_movie(movie_name,language,cast,movie_release,director,rating,rating_count)values('$movie_name','null','$cast','$release','$director',250,230)"; //echo $sql.'<br>'; //echo $sql_movie; mysql_query($sql_movie); $sqlcount = 'select max(id) jos_movie'; $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 span tags class=gb1 foreach($html->find('div.movitmngbox') $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' , $cinemaid = '1' , $long='32.726602' , $lat='74.857026'; elseif(strpos($temname,'indraaudi2') !== false) $trimname = 'indra audi 2' , $cinemaid = '2'and $long='32.726602' , $lat='74.857026'; elseif(strpos($temname,'indraaudi3') !== false) $trimname = 'indra audi 3'and $cinemaid = '3' , $long='32.726602' , $lat='74.857026'; elseif(strpos($temname,'apsra') !== false) $trimname = 'apsra' , $cinemaid = '4' , $long='32.700314' , $lat='74.858023'; else{ $trimname = trim(substr($name,18,strlen($name))) , $cinemaid = '5' , $long='32.7300' , $lat='74.8700' ; } //echo $tagtime->innertext.'<br/>'; $sql = "insert 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 ?>
here requirement.
i getting movie names in $movie_name array have appeneded names xml can moviedbid it. getting movieid successfully. want insert moviedb id respective movie.
please tell me wrong.
try this:
<?php $sql = ""; foreach ($arrtitle $movie_name) { $xml = simplexml_load_file("http://api.themoviedb.org/2.1/movie.search/en/xml/myapi/$movie_name"); foreach ($xml->movies->movie $movies) { $arrmovie_id = $movies->id; } $movie_ids = $arrmovie_id[0]; $arrstr = explode(':', $htmlshowtime); $release = substr($arrstr[3], 0, strlen($arrstr[3]) - 8); $director = substr($arrstr[5], 0, strlen($arrstr[5]) - 11); $sql .= "('$movie_name','null','$cast','$release','$director',250,230,'$movie_ids'),"; } $sql = substr($sql, 0, -1); $sql_movie = "insert `jos_movie`(`movie_name`,`language`,`cast`,`movie_release`,`director`,`rating`,`rating_count`,`movie_ids`) values" . $sql; ?>
Comments
Post a Comment