Jump to content

[SOLVED] How to count columns not rows


brooksh

Recommended Posts

So what I'm trying to do is add all the counts up. So let's say you have in the database:

title: one count: 3

title: two count: 2

title: one count: 5

 

title: one should equal 8 for count.

$sql="SELECT title,count FROM data WHERE id='$id' GROUP BY title";
$result = mysql_query($sql) or die('Query failed: ' . mysql_error());	

while($row = mysql_fetch_assoc($result))
{	
		$title=$row["title"];
		$count=$row["count"];
		$data[$title]=$count;
}

 

So something like this:

 

$sql="SELECT title,count FROM data WHERE id='$id' GROUP BY title";
$result = mysql_query($sql) or die('Query failed: ' . mysql_error());	

while($row = mysql_fetch_assoc($result))
{	
		$title=$row["title"];
		$count=$row["count"];

}
foreach ($title AS $value)
{
$data[$title]=$count;
}

Link to comment
https://forums.phpfreaks.com/topic/161473-solved-how-to-count-columns-not-rows/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.