co.ador Posted July 26, 2009 Share Posted July 26, 2009 <?php $query ="SELECT rating , COUNT(*) AS rating_counts FROM rating WHERE item_name = 'Jordan' GROUP BY rating"; $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); // see if any rows were returned if (mysql_num_rows($result) > 0) { $ratings = array_fill(1,5,0); $rowsCount = count($result); // assume $rows is the result array for($i=0;$i<$rowsCount;$i++) { $ratings[$result[$i]['rating']]++; echo '<h3>1 Star Active</h3> <ul class="rating onestar"> <li class="one"><a href="#" title="1 Star">1</a></li> <li class="two"><a href="#" title="2 Stars">2</a></li> <li class="three"><a href="#" title="3 Stars">3</a></li> <li class="four"><a href="#" title="4 Stars">4</a></li> <li class="five"><a href="#" title="5 Stars">5</a></li> <li class="total">[',$result[2],']</li> </ul> <h3>2 Stars Active</h3> <ul class="rating twostar"> <li class="one"><a href="#" title="1 Star">1</a></li> <li class="two"><a href="#" title="2 Stars">2</a></li> <li class="three"><a href="#" title="3 Stars">3</a></li> <li class="four"><a href="#" title="4 Stars">4</a></li> <li class="five"><a href="#" title="5 Stars">5</a></li> <li class="total">[40]</li> </ul> <h3>3 Stars Active</h3> <ul class="rating threestar"> <li class="one"><a href="#" title="1 Star">1</a></li> <li class="two"><a href="#" title="2 Stars">2</a></li> <li class="three"><a href="#" title="3 Stars">3</a></li> <li class="four"><a href="#" title="4 Stars">4</a></li> <li class="five"><a href="#" title="5 Stars">5</a></li> <li class="total">[60]</li> </ul> <h3>4 Stars Active</h3> <ul class="rating fourstar"> <li class="one"><a href="#" title="1 Star">1</a></li> <li class="two"><a href="#" title="2 Stars">2</a></li> <li class="three"><a href="#" title="3 Stars">3</a></li> <li class="four"><a href="#" title="4 Stars">4</a></li> <li class="five"><a href="#" title="5 Stars">5</a></li> <li class="total">[80]</li> </ul> <h3>5 Stars Active</h3> <ul class="rating fivestar"> <li class="one"><a href="#" title="1 Star">1</a></li> <li class="two"><a href="#" title="2 Stars">2</a></li> <li class="three"><a href="#" title="3 Stars">3</a></li> <li class="four"><a href="#" title="4 Stars">4</a></li> <li class="five"><a href="#" title="5 Stars">5</a></li> <li class="total">[100]</li> </ul>'; } } ?> Hey guys I want to give a little hand here I have an sql injection at the top and a for loop to print the total count of the 1 stars, 2 stars , 3 stars , 4 stars, and five stars of item_name= x but it is not working i think the $rows variable in the for loop is coming empty and the item_name= x in the sql injection need some type of value but i don't have any idea how to direct the rows and the item_name so it can properly work... Just give some knowledge been working in a little bit of what the guys has given me. I think the item_name need to be placed auto variable not manually one so every time an x user click on a item the sql injection bring the variable value in the item_name value and then the for loop get in charge of counting and printing the value of star 1, stars 2, etc of that item... drop some of your understanding of this thanks Link to comment https://forums.phpfreaks.com/topic/167530-i-need-help-counting-the-number-of-stars/ Share on other sites More sharing options...
abazoskib Posted July 26, 2009 Share Posted July 26, 2009 co.ador, sql injection is a type of attack i.e. injecting unwanted sql queries into text fields on a web page to gain access to information. besides that, when you select count(*) of a table, you get the total rows in that table. other than that i dont think i understand your question. Link to comment https://forums.phpfreaks.com/topic/167530-i-need-help-counting-the-number-of-stars/#findComment-883496 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.