gpt4 book ai didi

php - sql :how to store the query result count directly to a infobox

转载 作者:行者123 更新时间:2023-11-29 03:07:30 25 4
gpt4 key购买 nike

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

我有一个函数:

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;
}

并且我必须将输出查询结果存储在“No of Incidents”中;

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>"

我必须将此事件值固定为“No of Incidents”:

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”变量中显示查询值?

最佳答案

对非 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 的新手,所以也许不是最好的答案,但我最近自己做了一个这样的问题,我认为这对你有用。 (作为一个新手,如果你愿意的话,用一小撮盐来接受它,哦,还有哈希......)

关于php - sql :how to store the query result count directly to a infobox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13152433/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com