co.ador Posted July 26, 2009 Share Posted July 26, 2009 looking for an sql injection where I can display the total sum of each star that a item has been rated by users to better explain it I will post a pictures so you can see. I will also post a database dump so you guys have an idea of how the database is built. database dump -- -- Database: `menu` -- -- -------------------------------------------------------- -- -- Table structure for table `rating` -- CREATE TABLE IF NOT EXISTS `rating` ( `item_name` varchar(100) NOT NULL, `ip_address` varchar(15) NOT NULL, `rating` tinyint(1) NOT NULL, `date_rated` date NOT NULL, PRIMARY KEY (`item_name`,`ip_address`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; The rating field is a number from 1 to 5 is recorded in there and it will vary according to the user rate. and that's the field I want to retrieve and sum all the 1 rating the 2 rating 3 ratings of item-name "X" Quote Link to comment https://forums.phpfreaks.com/topic/167453-help-me-build-rating-query-to-add-rating/ Share on other sites More sharing options...
smerny Posted July 26, 2009 Share Posted July 26, 2009 select where rating = 1 mysql_num_rows that doesn't look like a nike jordan shoe btw Quote Link to comment https://forums.phpfreaks.com/topic/167453-help-me-build-rating-query-to-add-rating/#findComment-882980 Share on other sites More sharing options...
co.ador Posted July 26, 2009 Author Share Posted July 26, 2009 Ok mysql numbers of rows "SELECT rating FROM rating WHERE rating= 1"; $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); if (mysql_num_rows($result) > 0) { sum rating} "SELECT rating FROM rating WHERE rating= 2"; $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); if (mysql_num_rows($result) > 0) { sum rating} $query ="SELECT rating FROM rating WHERE rating= 3"; $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); if (mysql_num_rows($result) > 0) { sum rating} I just throwing something, Please explain anything you do here guys thank you... I am just doing something crazy here so you can Quote Link to comment https://forums.phpfreaks.com/topic/167453-help-me-build-rating-query-to-add-rating/#findComment-882987 Share on other sites More sharing options...
vineld Posted July 26, 2009 Share Posted July 26, 2009 If you do these queries often maybe you should begin thinking about storing the total number of votes in a separate table. Quote Link to comment https://forums.phpfreaks.com/topic/167453-help-me-build-rating-query-to-add-rating/#findComment-882992 Share on other sites More sharing options...
co.ador Posted July 26, 2009 Author Share Posted July 26, 2009 ok, I will have to do that and maybe do a whole table just for the numbers of each star then i will have to change the whole sql injections. Quote Link to comment https://forums.phpfreaks.com/topic/167453-help-me-build-rating-query-to-add-rating/#findComment-882993 Share on other sites More sharing options...
co.ador Posted July 26, 2009 Author Share Posted July 26, 2009 how it would look building a new table ? Quote Link to comment https://forums.phpfreaks.com/topic/167453-help-me-build-rating-query-to-add-rating/#findComment-882994 Share on other sites More sharing options...
fenway Posted August 3, 2009 Share Posted August 3, 2009 Sounds like you just need a COUNT and a GROUP BY. Quote Link to comment https://forums.phpfreaks.com/topic/167453-help-me-build-rating-query-to-add-rating/#findComment-889923 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.