我有以下代码:
我不想计算特定线程/查找的答案数量。比如,有多少人回复此查询。
function lookup()
{
$sql = "SELECT * FROM lookup
INNER JOIN lookupCategories
ON lookup.FK_lookupCategory=lookupCategories.lookupCategoriesId
INNER JOIN lookupType
ON lookup.FK_lookupType=lookupType.lookupTypeId
LEFT JOIN authentication
ON lookup.FK_lookupUserId=authentication.userId
LEFT JOIN freelanceTypes
ON lookup.FK_freelanceTypes=freelanceTypes.freelanceTypesId
LEFT JOIN lookupAnswer
ON lookup.lookupId=lookupAnswer.FK_lookupId
ORDER BY lookupId DESC
LIMIT 5";
$result = mysql_query($sql)or die(mysql_error());
$viewLookup = Array();
while($row=mysql_fetch_assoc($result)):
$viewLookup[$row['lookupId']]['lookupId'] = $row['lookupId'];
$viewLookup[$row['lookupId']]['lookupHeader'] = $row['lookupHeader'];
$viewLookup[$row['lookupId']]['lookupSubHeader'] = $row['lookupSubHeader'];
$viewLookup[$row['lookupId']]['lookupContent'] = $row['lookupContent'];
$viewLookup[$row['lookupId']]['lookupDate'] = $row['lookupDate'];
$viewLookup[$row['lookupId']]['lookupCategory'] = $row['lookupCategoryName'];
$viewLookup[$row['lookupId']]['lookupType'] = $row['lookupTypeName'];
$viewLookup[$row['lookupId']]['lookupByUsername'] = $row['username'];
$viewLookup[$row['lookupId']]['lookupByUserId'] = $row['userId'];
$viewLookup[$row['lookupId']]['lookupFreelanceTypeId'] = $row['FK_freelanceTypes'];
$viewLookup[$row['lookupId']]['freelanceWinner'] = $row['freelanceWinner'];
endwhile;
return $viewLookup;
}
我不想算一个帖子'答案'的数量。我的线程加入了查找。然后如你所见存储在一个数组中。
我如何计算答案,并将数字与其余数据一起存储在数组中?我试过这样做,但无法弄清楚出了什么问题。它只是返回,如果有或没有 - 1或NULL。
$viewLookup[$row['lookupId']]['countAnswers'] = count($row['lookupAnswerId']);
提前致谢:)
答案 0 :(得分:2)
$sql = select count(*)....
休息添加条件。