top movies Hits

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
phpcoder
Forum Contributor
Posts: 158
Joined: Sat Nov 02, 2002 1:18 pm
Location: Manchester, UK

top movies Hits

Post by phpcoder »

hello,
i have linux server that hosts movies on LAN.i want to display top 5 movies i.e viewed.
i have link, when user click on that link the movie start playing now i want to increment the counter in database for that specific movie, with out the user attention.
if i use form tag or query string in link then the user browser will direct to that page but i dont want to direct my user to that pagr the user can start viewing movies and movie counter increment with out user attantion plz help...
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

As soon as someone visits the page, add a query that updates the database for a specific movie ID. This update will make the current number 1 higher than it was previously.

Code: Select all

<?php
// set the variabls for the database access
$host = "";
$user = "";
$pass = "";
$db = "";
$table = "";

// connecting to db
$link = mysql_connect ($Host, $User, $Password);

// setting the query variable
// specify the movie id somehow, that will tell the db which movie to update
$q = "UPDATE $table SET hits=hits+1 WHERE movieid='$movieid'";

// running a query, invisible to a user
mysql_db_query ($db, $q, $link);

// now closing the connection
mysql_close ($Link)
?>
Never tested it, it should work in theory. :)
Post Reply