Reputation: 238
I am trying to show the points outside whileloop. I am fetching result like this.
Facebook
Twitter,Facebook,Instagram,Youtube
Facebook
Facebook
It fetches Facebook from each row and count no of times in the end.
<?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));
}
?>
Upvotes: 0
Views: 312
Reputation: 1529
Please try like this,
<?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;
?>
Upvotes: 2