Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Somebody please help me with Counting views on items with using MYSQL and PHP Thanks
Old 10-21-2007, 11:36 PM Somebody please help me with Counting views on items with using MYSQL and PHP Thanks
goheadtry's Avatar
Webmaster Talker

Posts: 730
Name: John
Location: United States of America, California
Trades: 0
Okay I want to store the result of a videos views using MYSQL and PHP.
Like a view counter on a webpage except each video needs it's own counter, but how do I get the script to update the video views and such, so when the page is viewed it will add +1 to the number of total views for that given video.
__________________
Free $1 gift card when you signup at
Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

goheadtry is offline
Reply With Quote
View Public Profile Visit goheadtry's homepage!
 
 
Register now for full access!
Old 10-22-2007, 12:44 AM Re: Somebody please help me with Counting views on items with using MYSQL and PHP Tha
stewart's Avatar
Novice Talker

Posts: 11
Name: Stewart Howe
Location: Denver, CO
Trades: 0
You will have to have a table or something in your MySQL database keeping track of all of your videos somehow obviously, and with a field saving the number of views...

So you would have to grab the value out of the MySQL database increase it by 1 and then save it back to the database.

ok i'll give a quick stab at an example...

Assuming you have a MySQL table named videos which has a field named views.
mysql table videos :
id | name | link | views
1 | Cool Vid | www.cool.com | 6

Code:
<?php
mysql_connect('localhost','root','r0x');
mysql_select_db('mycooldb');

$sql = mysql_query("SELECT * FROM `videos` WHERE `id`='1' ");
$getCount = mysql_fetch_row($sql);
$getCount = $getCount[3]; // fetch_row returns a numeric array
$getCount = $getCount++; // add one to the fetched number

mysql_query("UPDATE `videos` SET `views`='" . $getCount . "' WHERE `id`='1'");
// update the record with the new number of views

?>
There might be a syntax error or two in there, but thats the just of it.
__________________
stewart::howe
Web Developer & Programmer

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
| CelerLabs.com

Last edited by stewart; 10-22-2007 at 01:02 AM..
stewart is offline
Reply With Quote
View Public Profile Visit stewart's homepage!
 
Old 10-22-2007, 12:58 PM Re: Somebody please help me with Counting views on items with using MYSQL and PHP Tha
Experienced Talker

Posts: 45
Trades: 0
or "SET views = views + 1"
__________________
-sites/domains i have-
Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE
-
accesstimes is offline
Reply With Quote
View Public Profile
 
Old 10-22-2007, 04:27 PM Re: Somebody please help me with Counting views on items with using MYSQL and PHP Tha
stewart's Avatar
Novice Talker

Posts: 11
Name: Stewart Howe
Location: Denver, CO
Trades: 0
Quote:
Originally Posted by accesstimes View Post
or "SET views = views + 1"
yeah that would be much easier... i'm a dope.
__________________
stewart::howe
Web Developer & Programmer

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
| CelerLabs.com
stewart is offline
Reply With Quote
View Public Profile Visit stewart's homepage!
 
Old 10-22-2007, 11:58 PM Re: Somebody please help me with Counting views on items with using MYSQL and PHP Tha
goheadtry's Avatar
Webmaster Talker

Posts: 730
Name: John
Location: United States of America, California
Trades: 0
Also is it possible to execute to mysql queries with different user names and tables on the same page?.(If so how do I do this, I have yet to find a way.)
__________________
Free $1 gift card when you signup at
Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

goheadtry is offline
Reply With Quote
View Public Profile Visit goheadtry's homepage!
 
Old 10-23-2007, 07:40 AM Re: Somebody please help me with Counting views on items with using MYSQL and PHP Tha
Foundationflash's Avatar
Ultra Talker

Posts: 410
Name: Harry Burt
Location: Colchester, Essex, England
Trades: 0
Surely tables aren't the problem? THe table name is in the mysql query. I don't know about re-connecting though.
__________________
Foundation Flash tutorials :
Please login or register to view this content. Registration is FREE


New Dreamed Up Web Design:
Please login or register to view this content. Registration is FREE
Foundationflash is offline
Reply With Quote
View Public Profile Visit Foundationflash's homepage!
 
Reply     « Reply to Somebody please help me with Counting views on items with using MYSQL and PHP Thanks
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.23057 seconds with 12 queries