frobak Posted March 15, 2009 Share Posted March 15, 2009 Hi I am trying to count the number of instances of a field in a database table. So basically i want it to count how many times a value occurs and group them by value. I then want to display each count instance seperately. How would i get the result from the array and into a variable so i can use it? <?php include("includes/db_connect.inc.php"); $sql = "SELECT downloadid, COUNT(*) FROM downloadcount GROUP BY downloadid "; $result = mysql_query($sql); $row = mysql_fetch_array($result); $num1 = mysql_num_rows($row); ?> Link to comment https://forums.phpfreaks.com/topic/149568-counting-instances-of-row-field/ Share on other sites More sharing options...
Daniel0 Posted March 16, 2009 Share Posted March 16, 2009 mysql_fetch_array only fetches a single row and moves the cursor one position forward. When there are no more rows it returns false. You can use a while loop to get all the rows. The loop will run as long as the condition is true and will therefore terminate when there are no rows left. while ($row = mysql_fetch_array($result)) { // do as you want with each $row here } Link to comment https://forums.phpfreaks.com/topic/149568-counting-instances-of-row-field/#findComment-785652 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.