Jump to content

beginner here, need a little help


cat250

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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. :)

Link to comment
Share on other sites

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"]; }

?>

Link to comment
Share on other sites

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>"; }
?>

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

 

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.

Link to comment
Share on other sites

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 :(

Link to comment
Share on other sites

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.

:confused:

Link to comment
Share on other sites

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.  ;D

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.