alexville Posted December 27, 2008 Share Posted December 27, 2008 $a = mysql_query("SELECT SUM(`views`)FROM games WHERE uploader = '$session->username'"); I want to get the result (the total views) into a variable. Can anyone help? ??? Quote Link to comment https://forums.phpfreaks.com/topic/138561-solved-how-do-i-get-the-result-of-this-mysql-query/ Share on other sites More sharing options...
premiso Posted December 27, 2008 Share Posted December 27, 2008 mysql_result, mysql_fetch_array, mysql_fetch_row.....etc etc. Quote Link to comment https://forums.phpfreaks.com/topic/138561-solved-how-do-i-get-the-result-of-this-mysql-query/#findComment-724493 Share on other sites More sharing options...
MadTechie Posted December 27, 2008 Share Posted December 27, 2008 $a = mysql_query("SELECT SUM(`views`) FROM games WHERE uploader = '$session->username'"); $views = mysql_fetch_array($a); $views = $views[0]; echo $views; Quote Link to comment https://forums.phpfreaks.com/topic/138561-solved-how-do-i-get-the-result-of-this-mysql-query/#findComment-724494 Share on other sites More sharing options...
alexville Posted December 27, 2008 Author Share Posted December 27, 2008 $a = mysql_query("SELECT SUM(`views`) FROM games WHERE uploader = '$session->username'"); $views = mysql_fetch_array($a); $views = $views[0]; echo $views; Awesome man, just awesome! Happy holidays! Quote Link to comment https://forums.phpfreaks.com/topic/138561-solved-how-do-i-get-the-result-of-this-mysql-query/#findComment-724496 Share on other sites More sharing options...
alexville Posted December 27, 2008 Author Share Posted December 27, 2008 One more thing, how would I check if the result was empty, and instead say it was 0 views? Quote Link to comment https://forums.phpfreaks.com/topic/138561-solved-how-do-i-get-the-result-of-this-mysql-query/#findComment-724497 Share on other sites More sharing options...
premiso Posted December 27, 2008 Share Posted December 27, 2008 $a = mysql_query("SELECT SUM(`views`) FROM games WHERE uploader = '$session->username'"); $views = 0; if (mysql_num_rows($a) > 0) { $views = mysql_fetch_array($a); $views = $views[0]; } echo $views; Quote Link to comment https://forums.phpfreaks.com/topic/138561-solved-how-do-i-get-the-result-of-this-mysql-query/#findComment-724498 Share on other sites More sharing options...
alexville Posted December 27, 2008 Author Share Posted December 27, 2008 One more thing, how would I check if the result was empty, and instead say it was 0 views? Okay, It works when the person has more than 0 views, but when they have no views it just shows up as this: Your games have received views all together! The number zero doesnt show up where it should be between received and views. $a = mysql_query("SELECT SUM(`views`) FROM games WHERE uploader = '$session->username'"); $views = 0; if (mysql_num_rows($a) > 0) { $views = mysql_fetch_array($a); $views = $views[0]; } echo "Your games have received <strong>$views</strong> views all together!"; Quote Link to comment https://forums.phpfreaks.com/topic/138561-solved-how-do-i-get-the-result-of-this-mysql-query/#findComment-724501 Share on other sites More sharing options...
premiso Posted December 27, 2008 Share Posted December 27, 2008 $a = mysql_query("SELECT SUM(`views`) FROM games WHERE uploader = '$session->username'"); $views = 0; if (mysql_num_rows($a) > 0) { $views = mysql_fetch_array($a); $views = $views[0]; if (empty($views) || $views == "") $views = 0; } echo $views; Try that. It is simple if logic.... Quote Link to comment https://forums.phpfreaks.com/topic/138561-solved-how-do-i-get-the-result-of-this-mysql-query/#findComment-724502 Share on other sites More sharing options...
alexville Posted December 27, 2008 Author Share Posted December 27, 2008 Okay thanks that worked Quote Link to comment https://forums.phpfreaks.com/topic/138561-solved-how-do-i-get-the-result-of-this-mysql-query/#findComment-724503 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.