last day (14 days later) » 

05:05
0
A: Irregularity in fetching the details with array

NullVoidYou need to execute like this in for loop where multiple images are found. I created list of multiple movie listing in XML file and test below code. //$movies = $xml->movies; $movies = $xml->xpath("//movies/descendant::movie"); //echo "<pre>";print_r($movies);die; //$images = $xml->x...

only one movie got inserted :( and that too with image Array id was correct
Did you noticed my updated code than your once? I am fetching multiple movies and based on that one movie I am selecting their images and put those Image Urls in $imageUrl and afterwards creating string with multiple Image Urls per Movie.
But the same didnt worked for the multiple movies . It worked well for fetching the correct for single movie But when i used you code in my file, it fetched only one movie
with <code>$movies = $xml->xpath("//movies/descendant::movie");
echo "<pre>";print_r($movies);die;</code> you will get all movies from your return XML.
yeah I getting the mvoies but while insert I can only see 1 movie inserted, rest wont show up in DB
05:05
See above image of insertion of multiple movies in table. For test purpose I have created two fields id and movieimage. I could successfully inserted movies.
Hi
You there?
yes
I am here
Tell me
Actually I am again integerating my code
with yours
lemme run it again
I am still not able to make it work
here is full code of script
<?php
// Include the 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 to get the RSS feed into a PHP string variable.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'http://www.asklaila.com/movies/Jammu/?feed=rss_2.0');
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$xml = curl_exec($ch);
curl_close($ch);

$arrData = array();
can you see full lcode
I havent integerated your code in it
05:13
Yes. Let me check your edited code
it is the normal code which I am having now
NO. You have not integrated my code :(
yes
$movies = $xml->xpath("//movies/descendant::movie");
//echo "<pre>";print_r($movies);die;
//$images = $xml->xpath("//image");
foreach ($movies as $movie){
echo $arrMovie_id = $movie->id;
$images = $movie->xpath("//image");
//echo "<pre>";print_r($images);
$imageUrl = array();
foreach ($images as $image){
if($image['size'] == "thumb" && $image['type']=="poster"){
$imageUrl[] = $image['url'];
}
}

//then you need to implode $imageUrl array to string so that you can add multiple found image urls
$imageUrl = implode(",", $imageUrl);
i just showed you mine existing
<?php
// Include the 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 to get the RSS feed into a PHP string variable.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'http://www.asklaila.com/movies/Jammu/?feed=rss_2.0');
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$xml = curl_exec($ch);
curl_close($ch);

$arrData = array();
05:17
You have to use $movies = $xml->xpath("//movies/descendant::movie"); and not $movies = $xml->movies->movie;
here is full code with your integeration
still it wont show up all the movies
Have you looked up what I send you after you sent your code/
$movies = $xml->xpath("//movies/descendant::movie");
//echo "<pre>";print_r($movies);die;
//$images = $xml->xpath("//image");
foreach ($movies as $movie){
echo $arrMovie_id = $movie->id;
$images = $movie->xpath("//image");
//echo "<pre>";print_r($images);
$imageUrl = array();
foreach ($images as $image){
if($image['size'] == "thumb" && $image['type']=="poster"){
$imageUrl[] = $image['url'];
}
}

//then you need to implode $imageUrl array to string so that you can add multiple found image urls
$imageUrl = implode(",", $imageUrl);
Yeah I checked
and see my latest script shared with you above
it includes your code too
where?
above
ok lemme share it again
<?php
// Include the 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 to get the RSS feed into a PHP string variable.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'http://www.asklaila.com/movies/Jammu/?feed=rss_2.0');
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$xml = curl_exec($ch);
curl_close($ch);

$arrData = array();
here the above has yoru script integerated
05:22
Now it shows you have integrated ;)
Have you uncommented mysql_query($sql_movie);?
yes
Now you should be able to insert multiple movies in table.
When I run with your code
it only echo
it wont show other movies
and in DB also it inserts this row only
string(12) "Go Goa Gone " string(6) "Gippi " 189800insert into jos_movie(movie_name,language,cast,movie_release,director,rating,rating_count,movie_ids,image)values('Gippi ','null','Taaha Shah, Riya Vij, Divya Dutta',' May 10, 2013 ',' Vishal–Shekhar ',250,230,'189800','http://d3gtl9l2a4fn1j.cloudfront.net/t/p/w92/8xYyjdBVDqMYjrDTYJDy4GhGmLF.jpg')
string(19) "Shootout at Wadala " string(23) "Lucky Di Unlucky Story " string(11) "Aashiqui 2 "
string(19) "Shootout at Wadala " string(23) "Lucky Di Unlucky Story " string(11) "Aashiqui 2 " movies are not get inserted
string(6) "Gippi " 189800insert into jos_movie(movie_name,language,cast,movie_release,director,rating,rating_count,mo‌​vie_ids,image)values('Gippi ','null','Taaha Shah, Riya Vij, Divya Dutta',' May 10, 2013 ',' Vishal–Shekhar ',250,230,'189800','http://d3gtl9l2a4fn1j.cloudfront.net/t/p/w92/8xYyjdBVDqMYjrD‌​TYJDy4GhGmLF.jpg')
05:30
2 mins
yeah sure
//Create array of before the for loop of $movies

//in loop at last and not execute mysql_query in loop
$arrSql[] = "('$arrMovie_id','$imageUrl')";

echo $sql_movie = "insert into dbmovies(id,movieimage)values(".implode(",", $arrSql).")";
mysql_query($sql_movie);
change my table name dbmovies with you query
<?php
// Include the 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 to get the RSS feed into a PHP string variable.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'asklaila.com/movies/Jammu/…');
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.
I have integrated changes in your code too :)
Actually now we're executing query only once after loop is executed.
It will create this type of insert query
INSERT INTO `dbmovies` (`id`, `movieimage`) VALUES
(191562, 'http://d3gtl9l2a4fn1j.cloudfront.net/t/p/w92/cSDvyWmh7rSD7WtSoXScVw3GDnD.jpg,http://d3gtl9l2a4fn1j.cloudfront.net/t/p/w92/cSDvyWmh7rSD7WtSoXScVw3GDnD.jpg,http://d3gtl9l2a4fn1j.cloudfront.net/t/p/w92/cSDvyWmh7rSD7WtSoXScVw3GDnD.jpg'),
(201562, 'http://d3gtl9l2a4fn1j.cloudfront.net/t/p/w92/cSDvyWmh7rSD7WtSoXScVw3GDnD.jpg,http://d3gtl9l2a4fn1j.cloudfront.net/t/p/w92/cSDvyWmh7rSD7WtSoXScVw3GDnD.jpg,http://d3gtl9l2a4fn1j.cloudfront.net/t/p/w92/cSDvyWmh7rSD7WtSoXScVw3GDnD.jpg'),
05:48
I am checking please wait
I dont know why it worked for you
for me I am still
:(
here is last code
What error you're getting or not inserting all records?
<?php
// Include the handy XML data extraction functions.
include 'xml_regex.php';
include 'simple_html_dom.php';

$con = mysql_connect('localhost', 'test', '@}%W^XlOaZIW');
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, 'http://www.asklaila.com/movies/Jammu/?feed=rss_2.0');
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$xml = curl_exec($ch);
curl_close($ch);
Do you see any error in that
this time same movie id and images added 4 times in DB
here
$arrSql = array();
foreach ($movies as $movie){ you have not declared array above
now also print $sql_movie; and see what it's printing
?
05:57
ok
$arrSql = array();
foreach ($movies as $movie){
echo $arrMovie_id = $movie->id;
$images = $movie->xpath("//image");
//echo "<pre>";print_r($images);
$imageUrl = array();
foreach ($images as $image){
if($image['size'] == "thumb" && $image['type']=="poster"){
$imageUrl[] = $image['url'];
}
}
for the above I declared
arrsql
only first movie got inserted
:(
if you run above script how many movies you are able to insert
In my case 3 movies
but actually 4 movies
are you able to get those movies images and Ids
:( I am unlucky to get the sae
Yes. I am able see it in myadmin
can you eacho your $sql_movie variable after loop? here
insert into jos_movie(movie_name,language,cast,movie_release,director,rating,rating_count,mo‌​vie_ids,image) values 189800insert into jos_movie(movie_name,language,cast,movie_release,director,rating,rating_count
insert into jos_movie(movie_name,language,cast,movie_release,director,rating,rating_count,mo‌​vie_ids,image) values insert into jos_movie(movie_name,language,cast,movie_release,director,rating,rating_count,mo‌​vie_ids,image) values insert into jos_movie(movie_name,language,cast,movie_release,director,rating,rating_count,mo‌​vie_ids,image) values
values is blank
here is the echo
then print the echo "<pre>";print_r($arrSql); out side loop and paste it here
06:08
insert into jos_movie(movie_name,language,cast,movie_release,director,rating,rating_count,mo‌​vie_ids,image) values 189800insert into jos_movie(movie_name,language,cast,movie_release,director,rating,rating_count,mo‌​vie_ids,image) values ('Gippi ','null','Taaha Shah, Riya Vij, Divya Dutta',' May 10, 2013 ',' Vishal–Shekhar ',250,230,'189800','http://d3gtl9l2a4fn1j.cloudfront.net/t/p/w92/8xYyjdBVDqMYjrD‌​TYJDy4GhGmLF.jpg')
Array
(
)
189800insert into jos_movie(movie_name,language,cast,movie_release,director,rating,rating_count,movie_ids,image) values ('Gippi ','null','Taaha Shah, Riya Vij, Divya Dutta',' May 10, 2013 ',' Vishal–Shekhar ',250,230,'189800','http://d3gtl9l2a4fn1j.cloudfront.net/t/p/w92/8xYyjdBVDqMYjrDTYJDy4GhGmLF.jpg')
Array
(
[0] => ('Gippi ','null','Taaha Shah, Riya Vij, Divya Dutta',' May 10, 2013 ',' Vishal–Shekhar ',250,230,'189800','http://d3gtl9l2a4fn1j.cloudfront.net/t/p/w92/8xYyjdBVDqMYjrDTYJDy4GhGmLF.jpg')
There is still something wrong in your code.
You should see like. Output of echo "<pre>";print_r($arrSql);
Means array with multiple values
:(
for other movies the array is blank
<?php
// Include the handy XML data extraction functions.
include 'xml_regex.php';
include 'simple_html_dom.php';

$con = mysql_connect('localhost', 'test', '@}%W^XlOaZIW');
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, 'http://www.asklaila.com/movies/Jammu/?feed=rss_2.0');
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$xml = curl_exec($ch);
curl_close($ch);
I see your code here
$movie_name = $arrTitle[0];

$apiKey = '30f44b6ef9472d414e50d2acaa058b60';
$url = sprintf('api.themoviedb.org/2.1/…"%s"', $apiKey, rawurlencode(trim($movie_name)));
You're just giving one movie name then you will definitely get one movie not other
:(
You had talked in question comment that you will have multiple movie list for that I suggested above code
oh
:(
i am sorry for misunderstanding
Above code is for multi movie listing and you're passing only specific movie name in URL then you'll get only one movie
06:16
ohk
Then How will you get multiple movie list?
its cheching for movies 1 by 1
Now this means that your problem is solved
but still movies details are not coming
:(
AS you're fetching specific movies and your show your insert query that you're getting one movie details at a time then there should not be an issue
For that you have to check your CURL and whole code.
Ok
06:21
thanks
I will check that
Thanks you for your wonderful help
:LD
answer accpted
:)
Thank you :)

last day (14 days later) »