我有一个查询,它返回活动和非活动帖子的数量,以及特定的帖子详细信息。这是查询
$fetch = mysql_query("SELECT SQL_CALC_FOUND_ROWS * FROM
(SELECT DISTINCT propertyID, streetAddress, city FROM residence.property
WHERE residence.contact.contactEmailAddress1 ='$contactEmailAddress1' AND activePosting = '0') inactposts,
(SELECT FOUND_ROWS() AS 'inactiveCount') inact,
(SELECT DISTINCT propertyID, streetAddress, city FROM residence.property
INNER JOIN contact ON residence.contact.ContactID = residence.property.ContactID
WHERE residence.contact.contactEmailAddress1 ='$contactEmailAddress1' AND activePosting = '1') actposts,
(SELECT FOUND_ROWS() AS 'activeCount') act;")
or die('<li class=error>Ooops</li>'.mysql_error());
该查询在我的网页中有效。在 MySQL Workbench 中,它返回如下内容:
propID address city inactCount propID address city actCount
366 110 Main Street Perinton 1 352 3 Some Place Perinton 3
366 110 Main Street Perinton 1 353 5 Joe Place Perinton 3
366 110 Main Street Perinton 1 356 111 Main Perinton 3
对我来说问题是子查询结果的 2 部分没有标识符(我可以找到),所以在 PHP 服务器构造的 HTML 中,我无法将列表分成非活动帖子(inactposts ) 和活动帖子 (actposts)。目前 HTML仅返回活动帖子的列表。我尝试将临时表的名称“inactposts”放在各个地方,但我只是收到错误消息
这是进行 HTML 构造的 PHP:
if( mysql_num_rows($fetch) ) {
while ($row = mysql_fetch_array($fetch)) {
$inactiveCount = $row["inactiveCount"];
$activeCount = $row["activeCount"];
$storedStreetAddress = $row["streetAddress"];
$storedCity3 = $row['city3'];
$error_NumberInactives = "<ul>You have $activeCount active posts and $inactiveCount inactive posts.</ul>";
$error_List_Actives = "<li>Your $activeCount active posts are:</li>";
$errorMessages[0] = $error_NumberInactives;
$errorMessages[1] = $error_List_Actives;
$errorMessages[] = "<li> $storedStreetAddress, $storedCity3 </li>";
}else{ //error message}
如何从此查询构造单独的子查询结果列表?还是我需要不同的查询?