在 while 循环后显示结果计数

Show result count after while loop

我正在尝试显示 whileloop 之外的点。我正在获取这样的结果。

Facebook
Twitter,Facebook,Instagram,Youtube
Facebook
Facebook

它从每一行中获取 Facebook,并计算最后的次数。

<?php 
  $q = "select * FROM users";
  $r = mysql_query($q);
  $total = mysql_num_rows($r);

  while($row = mysql_fetch_assoc($r)) {
    $fb= $row['social'];
    $dbreq = implode(',',explode(',', $fb));
    $fa=array("Twitter,",",Instagram,","Youtube");
    $newstring = str_replace($fa, "", $dbreq);

    echo $points= count(explode(',', $newstring));
  }
?>

请这样试,

<?php 
$q = "select * FROM users";
$r = mysql_query($q);
$total = mysql_num_rows($r);
$cnt =0 ;
while($row = mysql_fetch_assoc($r)) {
$fb= $row['social'];
if (strpos($fb,'facebook') !== false) {
   $cnt++;
}
}
echo "TOTAL:".$cnt;
    ?>