[英]PHP - Count amount of rows joined
I'm having the following code: 我有以下代码:
I wan't to count how many Answers there is to a specific Thread/lookup. 我不会计算特定线程/查找有多少个答案。 Like, how many replied to this lookup.
就像有多少人回复了此查询。
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;
}
And I wan't to count the amount of 'answers' to a thread. 而且我也不想计算线程的“答案”数量。 My threads are joined to the lookup's.
我的线程已加入查找。 And afterwards stored in an array as you see.
然后存储在数组中,如您所见。
How would I count the answers, and store the number in the array together with the rest of my data? 我将如何计算答案,并将数字与其余数据一起存储在数组中? I have tried to do this, but can't figure out what's wrong.
我已尝试执行此操作,但无法找出问题所在。 It's just returning if there's something or not - 1 or NULL.
它只是返回是否有东西-1或NULL。
$viewLookup[$row['lookupId']]['countAnswers'] = count($row['lookupAnswerId']);
Thanks in advance :) 提前致谢 :)
$sql = select count(*)....
其余添加条件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.