0

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?

2
Contributors
1
Reply
3
Views
5 Years
Discussion Span
Last Post by diafol
0

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 />";
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.