cat250 Posted January 11, 2012 Share Posted January 11, 2012 First of all, sorry for my bad english. I have this: PHP Code: [select] $link = file_get_contents("http://www.imdbapi.com/?i=tt1285016"); $json = json_decode($link,true); echo $json["Title"]; and I want to replace tt1285016 with $info["id"]; (this is something from mysql, first time when i use ). If I put echo $info["id"]; it return exactly what i need: tt1421545. How can I do that? thank u very much and sorry again for bad enlighs, not native language. EDIT: Sorry for bad section, first time when i come here. Quote Link to comment https://forums.phpfreaks.com/topic/254782-beginner-here-need-a-little-help/ Share on other sites More sharing options...
Muddy_Funster Posted January 11, 2012 Share Posted January 11, 2012 this is actualy a PHP issue, but your solution is : ... $link_info = $info['id']; $link = file_get_contents("http://www.imdbapi.com/?i=$link_info"); $json = json_decode($link,true); echo $json["Title"]; ... Quote Link to comment https://forums.phpfreaks.com/topic/254782-beginner-here-need-a-little-help/#findComment-1306375 Share on other sites More sharing options...
cat250 Posted January 11, 2012 Author Share Posted January 11, 2012 thank u but i already tried that. Error message: Notice: Undefined index: Title in C:\xampp\htdocs\x.php on line 9 Line 9: echo $json["Title"]; So i tried echo $json; and now say "Array". what do? Quote Link to comment https://forums.phpfreaks.com/topic/254782-beginner-here-need-a-little-help/#findComment-1306377 Share on other sites More sharing options...
kickstart Posted January 11, 2012 Share Posted January 11, 2012 Hi Try a print_r($json); The error suggests that $json is an array which does not have an index of 'title'. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/254782-beginner-here-need-a-little-help/#findComment-1306383 Share on other sites More sharing options...
cat250 Posted January 11, 2012 Author Share Posted January 11, 2012 hi keith, thank u very much for reply too. i tried what u said, print_r($json); and i get: Array ( [Title] => The Social Network [Year] => 2010 [Rated] => PG-13 [Released] => 1 Oct 2010 [Genre] => Biography, Drama [Director] => David Fincher [Writer] => Aaron Sorkin, Ben Mezrich [Actors] => Jesse Eisenberg, Andrew Garfield, Justin Timberlake, Rooney Mara [Plot] => Harvard student Mark Zuckerberg creates the social networking website that would become known as Facebook, but is later sued by two brothers who claimed he stole their idea, and the co-founder who was later squeezed out of the business. [Poster] => http://ia.media-imdb.com/images/M/MV5BMTM2ODk0NDAwMF5BMl5BanBnXkFtZTcwNTM1MDc2Mw@@._V1_SX320.jpg [Runtime] => 2 hrs [Rating] => 8.0 [Votes] => 177854 [iD] => tt1285016 [Response] => True ) what do with 'Title' now? thank u again. Quote Link to comment https://forums.phpfreaks.com/topic/254782-beginner-here-need-a-little-help/#findComment-1306387 Share on other sites More sharing options...
kickstart Posted January 11, 2012 Share Posted January 11, 2012 Hi That suggests to me that when you change the link to get tt1421545 that it doesn't bring back the page you expect. Try $link = file_get_contents("http://www.imdbapi.com/?i=tt1421545"); $json = json_decode($link,true); echo "$link <br />"; print_r($json); All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/254782-beginner-here-need-a-little-help/#findComment-1306404 Share on other sites More sharing options...
cat250 Posted January 11, 2012 Author Share Posted January 11, 2012 thanks again {"Title":"The Social Network","Year":"2010","Rated":"PG-13","Released":"1 Oct 2010","Genre":"Biography, Drama","Director":"David Fincher","Writer":"Aaron Sorkin, Ben Mezrich","Actors":"Jesse Eisenberg, Andrew Garfield, Justin Timberlake, Rooney Mara","Plot":"Harvard student Mark Zuckerberg creates the social networking website that would become known as Facebook, but is later sued by two brothers who claimed he stole their idea, and the co-founder who was later squeezed out of the business.","Poster":"http://ia.media-imdb.com/images/M/MV5BMTM2ODk0NDAwMF5BMl5BanBnXkFtZTcwNTM1MDc2Mw@@._V1_SX320.jpg","Runtime":"2 hrs","Rating":"8.0","Votes":"177854","ID":"tt1285016","Response":"True"} Notice: Undefined variable: json in C:\xampp\htdocs\x.php on line 10 hmmm? so, if I use this: $alink = file_get_contents("http://www.imdbapi.com/?i=tt1285016"); $json = json_decode($link,true); echo $json["Title"]; return: The Social Network and that is ok. but i whant to change tt1285016 with $info["id"];... i really don't know what u do. thank u very much. Quote Link to comment https://forums.phpfreaks.com/topic/254782-beginner-here-need-a-little-help/#findComment-1306406 Share on other sites More sharing options...
Muddy_Funster Posted January 11, 2012 Share Posted January 11, 2012 I only gave you 4 lines of code, can we see your full page of code? Quote Link to comment https://forums.phpfreaks.com/topic/254782-beginner-here-need-a-little-help/#findComment-1306409 Share on other sites More sharing options...
cat250 Posted January 11, 2012 Author Share Posted January 11, 2012 sure. <?php mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("base") or die(mysql_error()); $f = mysql_query("SELECT * FROM movies") or die(mysql_error()); while($info = mysql_fetch_array($f)) { $link = file_get_contents("http://www.imdbapi.com/?i=tt1285016"); $json = json_decode($link,true); echo $json["Title"]; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/254782-beginner-here-need-a-little-help/#findComment-1306412 Share on other sites More sharing options...
Muddy_Funster Posted January 11, 2012 Share Posted January 11, 2012 what does this return? <?php mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("base") or die(mysql_error()); $f = mysql_query("SELECT id FROM movies") or die(mysql_error()); while($info = mysql_fetch_asocc($f)) { $tid= htmlencode $info['id']; $url = "http://www.imdbapi.com/?i=$tid" echo "<br>$url<br>"; $link = file_get_contents($url); $json = json_decode($link,true); print_r($json); echo "<br><br><strong>".$json['Title']."</strong><br><br>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/254782-beginner-here-need-a-little-help/#findComment-1306419 Share on other sites More sharing options...
cat250 Posted January 11, 2012 Author Share Posted January 11, 2012 what does this return? <?php mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("base") or die(mysql_error()); $f = mysql_query("SELECT id FROM movies") or die(mysql_error()); while($info = mysql_fetch_asocc($f)) { $tid= htmlencode $info['id']; $url = "http://www.imdbapi.com/?i=$tid" echo "<br>$url<br>"; $link = file_get_contents($url); $json = json_decode($link,true); print_r($json); echo "<br><br><strong>".$json['Title']."</strong><br><br>"; } ?> Parse error: syntax error, unexpected T_VARIABLE in C:\xampp\htdocs\x.php on line 6 i really don't understand. thank u again... any idea now? Quote Link to comment https://forums.phpfreaks.com/topic/254782-beginner-here-need-a-little-help/#findComment-1306421 Share on other sites More sharing options...
Muddy_Funster Posted January 11, 2012 Share Posted January 11, 2012 I missed the ; from the end of the line starting with $url add that in and see what happens. Quote Link to comment https://forums.phpfreaks.com/topic/254782-beginner-here-need-a-little-help/#findComment-1306422 Share on other sites More sharing options...
cat250 Posted January 11, 2012 Author Share Posted January 11, 2012 I missed the ; from the end of the line starting with $url add that in and see what happens. hehe, i saw that and added but still this error. Parse error: syntax error, unexpected T_VARIABLE in C:\xampp\htdocs\x.php on line 6 Quote Link to comment https://forums.phpfreaks.com/topic/254782-beginner-here-need-a-little-help/#findComment-1306423 Share on other sites More sharing options...
Muddy_Funster Posted January 11, 2012 Share Posted January 11, 2012 more sillyness on my part : remove the word "htmlencode" from this line: $tid= htmlencode $info['id']; Quote Link to comment https://forums.phpfreaks.com/topic/254782-beginner-here-need-a-little-help/#findComment-1306426 Share on other sites More sharing options...
kickstart Posted January 11, 2012 Share Posted January 11, 2012 and that is ok. but i whant to change tt1285016 with $info["id"];... i really don't know what u do. thank u very much. Ignore using $info for now. My suggested code had an alternative id hard coded in it. See what that returns. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/254782-beginner-here-need-a-little-help/#findComment-1306427 Share on other sites More sharing options...
cat250 Posted January 11, 2012 Author Share Posted January 11, 2012 more sillyness on my part : remove the word "htmlencode" from this line: $tid= htmlencode $info['id']; hehe, it's ok. now i get this: Fatal error: Call to undefined function mysql_fetch_asocc() in C:\xampp\htdocs\x.php on line 5 maybe is a little stupid for me but i never worked with mysql... so i really don't understand these errors... Quote Link to comment https://forums.phpfreaks.com/topic/254782-beginner-here-need-a-little-help/#findComment-1306428 Share on other sites More sharing options...
Muddy_Funster Posted January 11, 2012 Share Posted January 11, 2012 that ones my dyslexia kicking in >_< it should be "mysql_fetch_assoc()" Quote Link to comment https://forums.phpfreaks.com/topic/254782-beginner-here-need-a-little-help/#findComment-1306430 Share on other sites More sharing options...
cat250 Posted January 11, 2012 Author Share Posted January 11, 2012 and that is ok. but i whant to change tt1285016 with $info["id"];... i really don't know what u do. thank u very much. Ignore using $info for now. My suggested code had an alternative id hard coded in it. See what that returns. All the best Keith i hope i understood what u said... my english isn't good. i already tried what u gave and i get this: {"Title":"Dietro le mura del convento","Year":"2009","Rated":"N/A","Released":"N/A","Genre":"Comedy, Drama, Thriller, Crime, Mystery","Director":"Lodovico Gasparini","Writer":"N/A","Actors":"Nino Frassica, Simone Montedoro, Natalie Guetta, Francesco Scali","Plot":"N/A","Poster":"N/A","Runtime":"N/A","Rating":"N/A","Votes":"N/A","ID":"tt1421545","Response":"True"} Notice: Undefined variable: json in C:\xampp\htdocs\x.php on line 9 hope u didn't want to say something else. thank u boys. Quote Link to comment https://forums.phpfreaks.com/topic/254782-beginner-here-need-a-little-help/#findComment-1306431 Share on other sites More sharing options...
cat250 Posted January 11, 2012 Author Share Posted January 11, 2012 that ones my dyslexia kicking in >_< it should be "mysql_fetch_assoc()" while($info = mysql_fetch_assoc()) { Warning: mysql_fetch_assoc() expects at least 1 parameter, 0 given in C:\xampp\htdocs\x.php on line 5 unbelievable Quote Link to comment https://forums.phpfreaks.com/topic/254782-beginner-here-need-a-little-help/#findComment-1306433 Share on other sites More sharing options...
Muddy_Funster Posted January 11, 2012 Share Posted January 11, 2012 ahh. I only ment for you to change the letters in assoc: while($info = mysql_fetch_assoc($f)) { Quote Link to comment https://forums.phpfreaks.com/topic/254782-beginner-here-need-a-little-help/#findComment-1306435 Share on other sites More sharing options...
cat250 Posted January 11, 2012 Author Share Posted January 11, 2012 ahh. I only ment for you to change the letters in assoc: while($info = mysql_fetch_assoc($f)) { some progress here, i guess... for this: <?php mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("base") or die(mysql_error()); $f = mysql_query("SELECT * FROM movies") or die(mysql_error()); while($info = mysql_fetch_assoc($f)) { $tid= $info['id']; $url = "http://www.imdbapi.com/?i=$tid"; echo "<br>$url<br>"; $link = file_get_contents($url); $json = json_decode($link,true); print_r($json); echo "<br><br><strong>".$json['Title']."</strong><br><br>"; } ?> i get: http://www.imdbapi.com/?i=tt1285016 Array ( [Title] => The Social Network [Year] => 2010 [Rated] => PG-13 [Released] => 1 Oct 2010 [Genre] => Biography, Drama [Director] => David Fincher [Writer] => Aaron Sorkin, Ben Mezrich [Actors] => Jesse Eisenberg, Andrew Garfield, Justin Timberlake, Rooney Mara [Plot] => Harvard student Mark Zuckerberg creates the social networking website that would become known as Facebook, but is later sued by two brothers who claimed he stole their idea, and the co-founder who was later squeezed out of the business. [Poster] => http://ia.media-imdb.com/images/M/MV5BMTM2ODk0NDAwMF5BMl5BanBnXkFtZTcwNTM1MDc2Mw@@._V1_SX320.jpg [Runtime] => 2 hrs [Rating] => 8.0 [Votes] => 177854 [iD] => tt1285016 [Response] => True ) The Social Network http://www.imdbapi.com/?i=tt1324545 Array ( [Response] => Parse Error ) Notice: Undefined index: Title in C:\xampp\htdocs\muvi.php on line 12 so i tried: <?php mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("baza") or die(mysql_error()); $f = mysql_query("SELECT * FROM filme") or die(mysql_error()); while($info = mysql_fetch_assoc($f)) { $tid= $info['id']; $url = "http://www.imdbapi.com/?i=$tid"; $link = file_get_contents($url); $json = json_decode($link,true); echo "<strong>".$json['Title']."</strong><br><br>"; } ?> and i get: The Social Network Notice: Undefined index: Title in C:\xampp\htdocs\muvi.php on line 10 in mysql i have 2 "entries": tt1285016 - appear and tt1324545 - error. Quote Link to comment https://forums.phpfreaks.com/topic/254782-beginner-here-need-a-little-help/#findComment-1306436 Share on other sites More sharing options...
Muddy_Funster Posted January 11, 2012 Share Posted January 11, 2012 following the link to http://www.imdbapi.com/?i=tt1324545 you will see that the target page is returning the parse error, not your code. the problem is with the value of tt1324545 - the target site does not like it. revise the values in your database and make sure they are correct. Quote Link to comment https://forums.phpfreaks.com/topic/254782-beginner-here-need-a-little-help/#findComment-1306439 Share on other sites More sharing options...
cat250 Posted January 11, 2012 Author Share Posted January 11, 2012 following the link to http://www.imdbapi.com/?i=tt1324545 you will see that the target page is returning the parse error, not your code. the problem is with the value of tt1324545 - the target site does not like it. revise the values in your database and make sure they are correct. yes, i saw now. sorry and thank u very very much for your help, i think i couldn't solve this without you and Keith, ofc. many thanks again, have a nice day and a wonderful life. Quote Link to comment https://forums.phpfreaks.com/topic/254782-beginner-here-need-a-little-help/#findComment-1306441 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.