$query = "SELECT smg_from,COUNT(smg_to),smg_body FROM sc_messages WHERE smg_from=$social_mem_id GROUP BY smg_body DESC LIMIT 10"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ echo "There are ". $row['COUNT(smg_to)'] ." ". $row['smg_body'] ." items."; echo "<br />"; } Code (markup): RESULT: There are 8 hi items. There are 5 hey items. There are 1 hay items. How can I write this if statement: if array result contains a $row['COUNT(smg_to)'] > 5??? Any help would be greatly appreciated. Thanks.
Hi, is that you're asking for: $query = "SELECT smg_from, COUNT(smg_to), smg_body FROM sc_messages WHERE smg_from={$social_mem_id} GROUP BY smg_from,smg_body DESC HAVING(COUNT(smg_to)>5) LIMIT 10"; PHP:
echo "There are ". $row['COUNT(smg_to)'] ." ". $row['smg_body'] ." items."; PHP: it will like if($row['COUNT(smg_to)'] > 5) { echo "There are ". $row['COUNT(smg_to)'] ." ". $row['smg_body'] ." items."; } PHP:
$query = "SELECT smg_from,COUNT(smg_to) AS cnt, smg_body FROM sc_messages WHERE smg_from=$social_mem_id GROUP BY smg_body DESC LIMIT 10"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)) { echo "There are ". $row[cnt] ." ". $row['smg_body'] ." items."; echo "<br />"; } PHP:
$query = "SELECT smg_from,COUNT(smg_to) AS cnt, smg_body FROM sc_messages WHERE smg_from=$social_mem_id GROUP BY smg_body DESC LIMIT 10"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)) { echo "There are ". $row[cnt] ." ". $row['smg_body'] ." items."; echo "<br />"; } PHP: