murhapuro Posted January 15, 2008 Share Posted January 15, 2008 Greetings I have this rating script that shows ratings in stars. When visitors want to rate a dinner they have 3 choices: Food quality: ***** Service: ***** Price: ***** Now this rating system works like a dream, but what i would like to do is, ask PHP to count all those three and as result, show overall rating. Overal: ********** In 10 stars, now the script has 10 stars as option and i would use it in this case. I know some basic php, but very little. I'm trying to learn all the time, but this is beyond my skills. I added the script as detached, so people can see how it works. I use this to call the script, it also gets the id from database i created: Food quality: ***** <?php $query = "SELECT stars_ss FROM info WHERE (id ='$id');"; $result = mysql_query($query, $connection) or die("Error: " . mysql_error()); while ($row = mysql_fetch_array($result)) { echo rating_bar($row['stars_ss'],'5'); } ?> Service: ***** <?php $query = "SELECT stars_sq FROM info WHERE (id ='$id');"; $result = mysql_query($query, $connection) or die("Error: " . mysql_error()); while ($row = mysql_fetch_array($result)) { echo rating_bar($row['stars_sq'],'5'); } ?> Price: ***** <?php $query = "SELECT stars_ps FROM info WHERE (id ='$id');"; $result = mysql_query($query, $connection) or die("Error: " . mysql_error()); while ($row = mysql_fetch_array($result)) { echo rating_bar($row['stars_ps'],'5'); } ?> Now comes the last one, i know how to make it 10 stars. It is the number ´5´ that only needs to be changed '10', also i know how to make it unvotable, but how do i display it: Overal: ********** <?php <- but what comes in here??? -> ?> If anyone could help with this, i would be so very happy. I need this because, i have search option and i would like to call that overal in search. This would be so awesom to have, i just don't have the skills to do it yet. I would also display it at the top of each page. Thank you! Murhapuro [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/86114-need-help-making-php-count-3-sums-to-one-and-showing-results/ Share on other sites More sharing options...
adam291086 Posted January 15, 2008 Share Posted January 15, 2008 well the over all start should be out of 15, three categories all with 5 stars. Then for the over you could do $food = $row['stars_ss'] $service = $row['stars_sq'], $price = $row['stars_ps'], $overall = $food+$service+$prive Quote Link to comment https://forums.phpfreaks.com/topic/86114-need-help-making-php-count-3-sums-to-one-and-showing-results/#findComment-439728 Share on other sites More sharing options...
murhapuro Posted January 15, 2008 Author Share Posted January 15, 2008 It don't seem to work. Quote Link to comment https://forums.phpfreaks.com/topic/86114-need-help-making-php-count-3-sums-to-one-and-showing-results/#findComment-439748 Share on other sites More sharing options...
murhapuro Posted January 15, 2008 Author Share Posted January 15, 2008 Could the problem be that the ID is in (info) table and the rating information is in (rating) table? Quote Link to comment https://forums.phpfreaks.com/topic/86114-need-help-making-php-count-3-sums-to-one-and-showing-results/#findComment-439750 Share on other sites More sharing options...
adam291086 Posted January 15, 2008 Share Posted January 15, 2008 was there any errors? Post all your code between tags Quote Link to comment https://forums.phpfreaks.com/topic/86114-need-help-making-php-count-3-sums-to-one-and-showing-results/#findComment-439752 Share on other sites More sharing options...
murhapuro Posted January 15, 2008 Author Share Posted January 15, 2008 Here is all code that i use on the page that i display it in, not sure if i need to modify the source code of the rating script. <?php $t_host = 'localhost'; $t_user = 'sjhdsa'; $t_pass = 'ads2321'; $db = 'foodinfo'; $mytable = 'info'; $id = 'laxon_dinner'; $food = $row['laxon_dinner_so']; $service = $row['laxon_dinner_ef']; $price = $row['laxon_dinner_rs']; $overall = $food+$service+$price; $connection = mysql_connect($t_host,$t_user,$t_pass); if (!$connection) { die("database connection failed: " . mysql_error()); } mysql_select_db($db,$connection); if (!@db_select) { die("Database selection failed: " . mysql_error()); } ?> <?php require('_drawrating.php'); ?> OVERALL RATING <?php $query = "SELECT id FROM ratings WHERE (id ='$overall');"; $result = mysql_query($query, $connection) or die("Error: " . mysql_error()); while ($row = mysql_fetch_array($result)) { echo rating_bar($row['$overall'],'10','static'); } ?> It just don't work. No errors Quote Link to comment https://forums.phpfreaks.com/topic/86114-need-help-making-php-count-3-sums-to-one-and-showing-results/#findComment-439769 Share on other sites More sharing options...
murhapuro Posted January 15, 2008 Author Share Posted January 15, 2008 if you want to see the source code, its attached in the first post. Quote Link to comment https://forums.phpfreaks.com/topic/86114-need-help-making-php-count-3-sums-to-one-and-showing-results/#findComment-439772 Share on other sites More sharing options...
adam291086 Posted January 15, 2008 Share Posted January 15, 2008 this OVERALL RATING <?php $query = "SELECT id FROM ratings WHERE (id ='$overall');"; $result = mysql_query($query, $connection) or die("Error: " . mysql_error()); while ($row = mysql_fetch_array($result)) { echo rating_bar($row['$overall'],'10','static'); } should be something like OVERALL RATING <?php $query = "SELECT id FROM ratings; $result = mysql_query($query, $connection) or die("Error: " . mysql_error()); while ($row = mysql_fetch_array($result)) { $food = $row['stars_ss']; $service = $row['stars_sq']; $price = $row['stars_ps']; } $overall = $food+$service+$price; echo $overall; Quote Link to comment https://forums.phpfreaks.com/topic/86114-need-help-making-php-count-3-sums-to-one-and-showing-results/#findComment-439775 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.