2

我有一个信息框来显示事件的数量:

我有一个功能:

function getStateCounts()
{
    $query = sprintf("select t1.count, t2.State_name
        from (select count(*) as count, state
            from INC_DIST_SUMMARY S
                join SHAPE_LAYERS L on L.geo_id = S.shape_geo_id
            group by state) as t1, SHAPE_LAYER_STATE_DESC as t2 
            where t1.state=t2.state");

    $count = mysql_query($query);

    if (!$count) {
        echo "<error> Invalid query " . $query . "</error>"
        die("Invalid query: " . mysql_error());
    }

    return $count;
}

我必须将输出查询结果存储在“事件编号”中;

while ($item = mysql_fetch_array($result, MYSQL_ASSOC)) {
    echo "<item><title geoid='" . $item['GEO_ID'] . "'>" .
         $item['STATE_NAME']."(".($item['STATE_ABBR']).")" .
         "</title><description cong_dist='".$item['DIST_NAME']."'>";
    echo $item['STATE_ABBR'] . $item['DIST_NAME'] . " &lt;br/&gt";" **No of Incidents:";**
    echo $item['INC_COUNT'] . "</description>";
    echo "</item>"

我必须将此事件值修复为“事件数量”:

while ($item = mysql_fetch_array($count, MYSQL_ASSOC)) {
    echo "<summary>";
    echo "<state>".$count['STATE']."</state>";
    echo "<count>".$count['COUNT']."</count>" 
    echo "</summary>";
}

如何在“No of Incidents”变量中显示查询值?

4

1 回答 1

1

对非 COUNT(*) 查询执行 rowCount();

或者执行mysql(i)_num_rows

标记您使用的任何技术的结果 $rowscounted 并替换

if (!$count) {
            echo "<error> Invalid query " . $query . "</error>";
            die("Invalid query: " . mysql_error());
        }

        return $count;
}

和:

if ($rowscounted == 0) {
    echo "<error> Invalid query " . $query . "</error>";
        die("Invalid query: " . mysql_error());
    }
else {
echo '$rowscounted states were returned by your query.'
}

我是 php 新手,所以也许不是最好的答案,但我最近自己做了一个这样的问题,并认为这对你有用。(作为一个新手,如果你愿意的话,请加一点盐,哦,还有一个哈希......)

于 2012-11-01T19:11:50.013 回答