Buy Sell Discuss UK Domain Names at AcornDomains.co.uk Domain Sponsor

Today's Drop Dates are: 07-11-2011 or 14-11-2011   All times are GMT. The time now is 09:00:22 PM.
Domain Name Sales Domain Software Calculate UK Domain Drop Dates Domain Registration NameDrive Domain Parking Subscribe to our Domains For Sale newsletter
Go Back   Domain Forum Acorn Domains Buy Sell Auction UK Domains > Website Design and Promotion > Website Design > Scripts and Coding
Connect with Facebook

Scripts and Coding PHP, MySQL, scripts

Closed Thread
 
LinkBack Thread Tools Display Modes
Old 10-01-2010, 06:28:16 PM     #11 (permalink)
Junior Member
 
Join Date: Jan 2010
Posts: 14
Betty Boop is on a distinguished road

Here is another version of the code which I have been using and this does the same output as the one underneath it.

<form action='trial.php' method='GET'>

<input type="text" name="search_term"/>
<input type="submit" value="Find"/>

</form>

<?php
// the if statement if there is nothing in the search box
if(empty($_GET['search_term']))
{
print "This must not be left blank!";
exit(0);
}
$search = $_GET['search_term'];

//Url for imdb
$url = file_get_contents("http://www.deanclatworthy.com/imdb/?q=".urlencode($search));
$data =($url);

print $data;

2nd Version:



<form action='trial.php' method='GET'>

<input type="text" name="search_term"/>
<input type="submit" value="Find"/>

</form>

<?php
// the if statement if there is nothing in the search box
if(empty($_GET['search_term']))
{
print "This must not be left blank!";
exit(0);
}
$movie = $_GET['search_term'];

$movie = ("http://www.deanclatworthy.com/imdb/?q=");
$movie = explode(",". $movie);

$string = '{
"title":"",
"year":"",
"imdburl":"",
"country":"",
"languages":"",
"genres":"",
"rating":"",
"votes":"",
"usascreens":"",
"ukscreens":""
}';

$obj = json_decode($string);
printf('<a href="%s" title="%s">%s (%d)</a>', $obj->imdburl, $obj->title, $obj->title, $obj->year);

Any help would be much appreciated.
Betty Boop is offline  
Old 10-01-2010, 06:39:00 PM     #12 (permalink)
Junior Member
 
Join Date: Jan 2010
Posts: 14
Betty Boop is on a distinguished road

Works

I have just fiddled around with the code and at the moment it creates a link when the movie is searched and when you press the link it redirects you to the imdb web page!

I still need to add another api but at the moment it works. Thank you.
Betty Boop is offline  
Old 10-01-2010, 06:43:40 PM     #13 (permalink)
Junior Member
 
Join Date: Jan 2010
Posts: 14
Betty Boop is on a distinguished road

Query

Hi,

I just need to know exactly what this does:

$obj = json_decode($url);
printf('<a href="%s" title="%s">%s (%d)</a>', $obj->imdburl, $obj->title, $obj->title, $obj->year);

I know that it decodes the json into a php format. It does work which is great but if I want to add more details about the movie e.g. country I add that field as $obj->country after $obj->year and nothing appears?
Betty Boop is offline  
Old 10-01-2010, 06:52:09 PM     #14 (permalink)

 
davedevelopment's Avatar
 
Join Date: May 2009
Location: Brough, East Yorks
Posts: 988
davedevelopment has a reputation beyond reputedavedevelopment has a reputation beyond reputedavedevelopment has a reputation beyond reputedavedevelopment has a reputation beyond reputedavedevelopment has a reputation beyond reputedavedevelopment has a reputation beyond reputedavedevelopment has a reputation beyond reputedavedevelopment has a reputation beyond reputedavedevelopment has a reputation beyond reputedavedevelopment has a reputation beyond reputedavedevelopment has a reputation beyond repute

You will need to add another place holder in the first argument to the printf query. %s is the place holder for a string.
__________________
Me: Blog | Company | Twitter

Coming Soon: DaveDomains | DaveCatcher | FreeToReg.co.uk
davedevelopment is offline  
Old 11-01-2010, 02:01:14 PM     #15 (permalink)
Junior Member
 
Join Date: Jan 2010
Posts: 14
Betty Boop is on a distinguished road

Thanks alot, I will try that now and then see what happens.
Betty Boop is offline  
Old 11-01-2010, 02:07:09 PM     #16 (permalink)
Junior Member
 
Join Date: Jan 2010
Posts: 14
Betty Boop is on a distinguished road

Tables

Hi,

Does anyone know how to display the json output into a table?

I have tried some methods but it does not work.

Thanks alot everyone that has helped with the coding.
Betty Boop is offline  
Old 11-01-2010, 02:46:44 PM     #17 (permalink)
dtm

 
dtm's Avatar
 
Join Date: Jan 2009
Location: Cheshire / Warwickshire
Posts: 768
dtm has a reputation beyond reputedtm has a reputation beyond reputedtm has a reputation beyond reputedtm has a reputation beyond reputedtm has a reputation beyond reputedtm has a reputation beyond reputedtm has a reputation beyond reputedtm has a reputation beyond reputedtm has a reputation beyond reputedtm has a reputation beyond reputedtm has a reputation beyond repute

Quote:
Originally Posted by Betty Boop View Post
Hi,

Does anyone know how to display the json output into a table?

I have tried some methods but it does not work.

Thanks alot everyone that has helped with the coding.
The following two links may help:

This is very basic and not very useful:
Creating and Parsing JSON data with PHP

If you can implement this class could be useful:
Table Constructor (html table) - PHP Classes

Quote:
This class can be used to display an HTML table from array, JSON or XML.

It can traverse data from an array and generate an HTML table that displays that data.

It can also read data from a JSON or XML file and convert it into an array so it can also be displayed in an HTML table.

1. Simply to use
new Table ($data); // work with array
new Table ('data.json', 'json-file');
new Table ($json_string, 'json'); // work with json-string
new Table ('data.xml', 'xml-file'); // work with xml-file
new Table ($xml_string, 'xml'); // work with xml-string
2. Universal: array, xml, json
3. Quick
__________________
Club Classics - ASCII - YMN
dtm is offline  
Old 11-01-2010, 02:51:09 PM     #18 (permalink)
Junior Member
 
Join Date: Jan 2010
Posts: 14
Betty Boop is on a distinguished road

Hi,

Thanks a lot. Here is the code that I am working with:

$obj = json_decode($url);
printf('<a href="%s" title="%s">%s (%d) %s %s</a>', $obj->imdburl, $obj->title, $obj->title, $obj->year, $obj->country, $obj->genres);

I presume that I will need the

new Table ('data.json', 'json-file');
Betty Boop is offline  
Old 12-01-2010, 02:31:25 PM     #19 (permalink)
Junior Member
 
Join Date: Jan 2010
Posts: 14
Betty Boop is on a distinguished road

More problems!

Hi,

I have been trying to do this for ages now....here is the code I have got.

$obj = json_decode($url);

printf('%s (%d) %s %s %s', $obj->title, $obj->year, $obj->country, $obj->genres, $obj->rating);
printf('<a href="%s"> %s'</a>, $obj->imdburl);

I want to display the first printf without linking to the url, I want this information to be displayed in a table with html or php. With the 2nd printf I want a link called 'More Info' to take the user to the imdb page on the film that is searched.

Originally I had:

printf('<a href="%s" title="%s">%s (%d)</a>', $obj->imdburl, $obj->title, $obj->title, $obj->year);

This made the whole content hperlinked and when pressed it took the user to the imdb site with info about the film searched.

I probably haven't described it clearly but if anyone knows how to do this it would help a lot.

Thanks.
Betty Boop is offline  
Old 12-01-2010, 03:05:38 PM     #20 (permalink)

 
davedevelopment's Avatar
 
Join Date: May 2009
Location: Brough, East Yorks
Posts: 988
davedevelopment has a reputation beyond reputedavedevelopment has a reputation beyond reputedavedevelopment has a reputation beyond reputedavedevelopment has a reputation beyond reputedavedevelopment has a reputation beyond reputedavedevelopment has a reputation beyond reputedavedevelopment has a reputation beyond reputedavedevelopment has a reputation beyond reputedavedevelopment has a reputation beyond reputedavedevelopment has a reputation beyond reputedavedevelopment has a reputation beyond repute

This wont be exactly right, but should put you on track! No more help from me after this, you'll learn the most by finding your own way!

PHP Code:

<?php

$obj 
json_decode(file_get_contents($url));

?>
<table>
    <tr>
        <th>Title</th>
        <th>Year</th>
        <th>Country</th>
        <th>Genres</th>
        <th>Rating</th>
        <th>&nbsp;</th>
    </tr>
    <tr>
        <td><?php echo htmlentities($obj->title);?></td>
        <td><?php echo htmlentities($obj->year);?></td>
        <td><?php echo htmlentities($obj->country);?></td>
        <td><?php echo htmlentities($obj->genres);?></td>
        <td><?php echo htmlentities($obj->rating);?></td>
        <td><a href="<?php echo htmlentities($obj->imdburl);?>">More info</a></td> 
    </tr>
</table>
__________________
Me: Blog | Company | Twitter

Coming Soon: DaveDomains | DaveCatcher | FreeToReg.co.uk
davedevelopment is offline  
Closed Thread



Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Domain Name Community Replies Last Post
PHP include in a Smarty Template admin Scripts and Coding 1 13-05-2008 06:37:26 AM
PHP variable help purg General Board 4 04-03-2008 02:30:21 PM
Problem displaying Google Adsense. miked Website Design 2 20-07-2007 04:24:01 PM




All times are GMT. The time now is 09:00:22 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.6.0 RC 2
All content on Acorn Domains is member generated and is not moderated before posting. All content is viewed and used by you at your own risk and AD does not warrant the accuracy or reliability of any of the information. The views expressed are those of the individual contributors and not necessarily those of AD. Please contact us to report any issues or send a PM to "Admin".