Chesso Posted May 24, 2006 Share Posted May 24, 2006 Iv'e been trying to make a basic rating system that allows a user to click on one of five images, each representing a number from 1 to 5 (1,2,3,4 or 5) and somehow calculate a 1-5 rating from the results.I have tried a few things (although scarce from my findings) but nothing actually works as it is intended.So I have a simpler idea but need help, basically in my db/table i'm going to have an entry for each rating, for example: rate_1, rate_2, rate_3, rate_4 and rate_5. If a user pressed the image that corresponds to a rating of 3 then rate_3 will go up by one.The only way I can think of using this data is to find out which of those rate_x happens to have the highest number, so if rate_3 was the highest out of the lot then the rating of the particular file would be 3.Iv'e tryed using the MAX() php function but this is rather useless to me, I need to know *which* field was the highest out of the rate_x's not have the *actual* highest value returned.Is there any function that exists or a query that can tell me which field has the highest value? or perhaps there is another way of going about this? Quote Link to comment https://forums.phpfreaks.com/topic/10327-5-star-rating-system-for-downloadable-files/ Share on other sites More sharing options...
eves Posted May 24, 2006 Share Posted May 24, 2006 [code]$result = mysql_query("SELECT rate_1, rate_2, rate_3, rate_4, rate_5 FROM (TABLE) WHERE (CONDITION) ");$row = mysql_fetch_row($result); // use mysql_fetch_row to get an array with a numeric index// get the max value in the fields (rate_1, teate_2, rate....) and search for it in the array $row// array_keys will return an array based on the search made, thus you access it as $index[0]$index = array_keys($row,max($row)); //determine which field is the highest//order on this part depends on the order of the fields in the select queryswitch ($index[0]){ case 0: //rate_1 is the highest break; case 1: //rate_2 is the highest break; case 2: //rate_3 is the highest break; case 3: //rate_4 is the highest break; default: //rate_5 is the highest break;}[/code]hope that helps Quote Link to comment https://forums.phpfreaks.com/topic/10327-5-star-rating-system-for-downloadable-files/#findComment-38581 Share on other sites More sharing options...
Chesso Posted May 24, 2006 Author Share Posted May 24, 2006 Thanks alot!!! :) Quote Link to comment https://forums.phpfreaks.com/topic/10327-5-star-rating-system-for-downloadable-files/#findComment-38587 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.