i have a problem to count explode function, here is my coding

<?php

$query = "SELECT Indication, COUNT(Indication) FROM reg WHERE Indication IS NOT NULL AND Indication != '' GROUP BY Indication"; 
	 
$result = mysql_query ($query) or die(mysql_error());

while($row = mysql_fetch_array($result)){
$medic = explode(",", $row['Indication']);

				for($i = 0; $i < count($medic); $i++){
				echo "". $row['COUNT(Indication)'] ." - $medic[$i] ";
				echo "<br />";
									
				} 
                                }
?>

and my result is :

a -1
a - 1 b - 1 c - 1
b - 1 c - 1

but i want the answer like this:

a = 2
b = 2
c = 2

can someone help me?

Member Avatar for diafol

You can merge all the items into one array and then count the values with array_count_values.
I really don't know if this is what you want:

$myarray = Array();
while($row = mysql_fetch_array($result)){
  $medic = explode(",", $row['Indication']);
  $myarray = array_merge($myarray,$medic);
}
$counts = array_count_values($myarray);

foreach($counts as $key=>$value){
  echo "$key = $value<br />";
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.