我试图在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));
}
?>
答案 0 :(得分:2)
请尝试这样,
<?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;
?>