jj20051 Posted May 6, 2009 Share Posted May 6, 2009 I have a video website script that I'm modifying. I'm attempting to count the total number of video views that a user gets and then print it out. Each video is stored in the database with the number of views it's received. Bellow is my code, $id refers to the user's username... There are no errors, so I don't know what is wrong. The output is just "Views:" it should be "Views: 37" as I have manually done the math. The Table Name Is: video Some Collums In That Table: videoid, username, views // Retrieve all the data from the table $result = mysql_query("SELECT SUM(views) FROM video WHERE username = '$id'") or die(mysql_error()); // store the record of the table into $row $row = mysql_fetch_array( $result ); // Print out the contents of the entry echo "Views: ".$row['views']; Quote Link to comment https://forums.phpfreaks.com/topic/157014-solved-no-errors-but-it-still-doesnt-work/ Share on other sites More sharing options...
Northern Flame Posted May 6, 2009 Share Posted May 6, 2009 what number is exactly in the column views Quote Link to comment https://forums.phpfreaks.com/topic/157014-solved-no-errors-but-it-still-doesnt-work/#findComment-827120 Share on other sites More sharing options...
jj20051 Posted May 6, 2009 Author Share Posted May 6, 2009 There are 5 Rows ATM. In order the values are: 4, 15, 8, 5, 4. As more videos are added this will increase and I only want it to add together a single user's total video views. (whoever is logged in and viewing this page) Quote Link to comment https://forums.phpfreaks.com/topic/157014-solved-no-errors-but-it-still-doesnt-work/#findComment-827123 Share on other sites More sharing options...
Northern Flame Posted May 6, 2009 Share Posted May 6, 2009 you can give this a try: $result = mysql_query("SELECT SUM(`views`) FROM `video` WHERE `username` = '$id'") or die(mysql_error()); if that doesnt work, display the exact setup of your table Quote Link to comment https://forums.phpfreaks.com/topic/157014-solved-no-errors-but-it-still-doesnt-work/#findComment-827124 Share on other sites More sharing options...
jj20051 Posted May 6, 2009 Author Share Posted May 6, 2009 Still didn't work. Here is the table with all rows (screenshot): http://www.paydayvideos.com/errors.png Quote Link to comment https://forums.phpfreaks.com/topic/157014-solved-no-errors-but-it-still-doesnt-work/#findComment-827163 Share on other sites More sharing options...
jj20051 Posted May 6, 2009 Author Share Posted May 6, 2009 Any Ideas anyone? I'd love some help. Quote Link to comment https://forums.phpfreaks.com/topic/157014-solved-no-errors-but-it-still-doesnt-work/#findComment-827193 Share on other sites More sharing options...
xtopolis Posted May 6, 2009 Share Posted May 6, 2009 Well, have you tried pasting the query in your code directly in your phpMyAdmin? I'm fairly certain you need a GROUP BY clause to go with your sum... SELECT SUM(views) FROM video WHERE username = 'admin' GROUP BY username Quote Link to comment https://forums.phpfreaks.com/topic/157014-solved-no-errors-but-it-still-doesnt-work/#findComment-827200 Share on other sites More sharing options...
jj20051 Posted May 6, 2009 Author Share Posted May 6, 2009 Well, I typed it into phpmyadmin, and it came back as 38, which is the correct answer. So now it's just figuring out what's wrong with my php code and why it isn't printing. Quote Link to comment https://forums.phpfreaks.com/topic/157014-solved-no-errors-but-it-still-doesnt-work/#findComment-827206 Share on other sites More sharing options...
jj20051 Posted May 6, 2009 Author Share Posted May 6, 2009 Got it thanks... Quote Link to comment https://forums.phpfreaks.com/topic/157014-solved-no-errors-but-it-still-doesnt-work/#findComment-827207 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.