Develop PHP Website for Learning Web Design Free Online
  Home   |   Forums   |   DevCMS
  Join   |   Log In
 
   

Forum Index >> PHP and MySQL Forum

Holder
veiws + 1
   New topic    
 
veiws + 1
by Joesmith - Thu Jul 29, 2010 02:35:23 PM

in my database i have a table called videos and within that a row called views with a defult of 0 and it is a int

when the video is viewed i want the views to go up by 1 each time it is viewed

this is the current code i am using: - 

$newviews = $views + 1;
mysql_query("UPDATE videos SET veiws='$newviews' WHERE uid='$id'");

but that does not work i dont know why?


Joesmith
Forum & Site XP Level:

United Kingdom
somerset
taunton

CapricornCapricorn
Posts: 223
Joined: 07/03/10
Website: URL

RE: veiws + 1
by Lima - Thu Jul 29, 2010 02:49:11 PM

$views +1 

Where are you geting your views variable from ???
Lima
Forum & Site XP Level:

United Kingdom
BNE Barnet
London

GeminiGemini
Posts: 64
Joined: 06/16/10

RE: veiws + 1
by Adam - Thu Jul 29, 2010 02:49:42 PM

This would be more efficient doing it directly in the SQL and may fix your issue too:

mysql_query("UPDATE videos SET views=(views + 1) WHERE uid='$id' ");
Adam
Forum & Site XP Level:

United States of America
NC
Brevard

ScorpioScorpio
Posts: 4388
Joined: 04/20/08
Website: URL

RE: veiws + 1
by Joesmith - Thu Jul 29, 2010 02:53:11 PM

<? session_start();
require"scripts/connect_to_mysql.php";
$video = $_GET['video'];
$query = mysql_query("SELECT * FROM videos WHERE id = '$video'");
$numrows = mysql_num_rows($query);
if ($numrows > 0){
$row = mysql_fetch_assoc($query);
$id = $row['id'];
$user_id = $row['uid'];
$user_name = $row['username'];
$title = $row['name'];
$description = $row['description'];
$video = $row['id'];
$views = $row['views'];
$link = $row['link'];
$description = nl2br($description);
$description = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]","<a target='_blank' href=\"\\0\">\\0</a>", $description);?>

thats where i am getting the views from and even adams way wont work??
Joesmith
Forum & Site XP Level:

United Kingdom
somerset
taunton

CapricornCapricorn
Posts: 223
Joined: 07/03/10
Website: URL

RE: veiws + 1
by Lima - Thu Jul 29, 2010 02:54:29 PM

You can do it as Adam but you can do it like this !

Code:

$select_update = mysql_query("SELECT * FROM videos WHERE video='$video_id''");
while($row = mysql_fetch_assoc($select_update)){
$current = $row['views'];
$current++;

mysql_query("UPDATE topics SET views='$current'  WHERE uid='$id'");

}


Lima
Forum & Site XP Level:

United Kingdom
BNE Barnet
London

GeminiGemini
Posts: 64
Joined: 06/16/10

RE: veiws + 1
by Joesmith - Thu Jul 29, 2010 03:00:49 PM

i am using this code

$vid = $_GET['video'];
$select_update = mysql_query("SELECT * FROM videos WHERE id='$vid''");
while($row = mysql_fetch_assoc($select_update)){
$current = $row['views'];
$current++;

mysql_query("UPDATE topics SET views='$current'  WHERE id='$vid'");

the video i am currently watching is

www.something.com/viewvideo.php?video=11
Joesmith
Forum & Site XP Level:

United Kingdom
somerset
taunton

CapricornCapricorn
Posts: 223
Joined: 07/03/10
Website: URL

RE: veiws + 1
by Caliosg - Thu Jul 29, 2010 03:05:16 PM

i have a tutorial on views as well.
it's my only tutorial

works with mysql
Caliosg
Forum & Site XP Level:

United Kingdom
Gwynedd
Blaenau

CancerCancer
Posts: 87
Joined: 12/20/09
Website: URL

RE: veiws + 1
by Lima - Thu Jul 29, 2010 03:15:17 PM

joe is that code on top of your page ???
Lima
Forum & Site XP Level:

United Kingdom
BNE Barnet
London

GeminiGemini
Posts: 64
Joined: 06/16/10

RE: veiws + 1
by Joesmith - Thu Jul 29, 2010 03:16:01 PM

dont worry guys i have all this working now :D
Joesmith
Forum & Site XP Level:

United Kingdom
somerset
taunton

CapricornCapricorn
Posts: 223
Joined: 07/03/10
Website: URL

RE: veiws + 1
by Lima - Thu Jul 29, 2010 03:17:12 PM

where was the problem ?
Lima
Forum & Site XP Level:

United Kingdom
BNE Barnet
London

GeminiGemini
Posts: 64
Joined: 06/16/10

RE: veiws + 1
by Joesmith - Thu Jul 29, 2010 03:18:52 PM

using adams code i just used WHERE  vid="$vid"

$vid = $_GET['video'];
 thats it really lol thanks for all your help !!
Joesmith
Forum & Site XP Level:

United Kingdom
somerset
taunton

CapricornCapricorn
Posts: 223
Joined: 07/03/10
Website: URL

   New topic  
 
 
Arbitrary Links and Archives
Home
Active Forums
Members
SIte News
Link To Us
Gear
2009 Forum Archive
Programming Courses
Learn HTML
Learn CSS
Learn PHP
Learn MySQL
Learn Javascript
Learn jQuery
Learn ActionScript 3.0
Learn Java
Learn XML
DevelopPHP Requires Flash Player
Get Adobe Flash player
___________________________________________

Terms of Use  •  Privacy  •  Admin Notes

©2010 developphp.com   |   Powered By FlashBuildingHolder