PHP检查MySQL最后一行 [英] PHP Check MySQL Last Row
本文介绍了PHP检查MySQL最后一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个关于PHP的简单问题,以检查这是否是MySQL的最后一行.例如,我有以下代码:
I have a simple question regarding PHP to check if this is the last row of MySQL or not. For example I have this code :
$result = mysql_query("SELECT *SOMETHING* ");
while($row = mysql_fetch_array($result))
{
if (*this is the last row*)
{/* Do Something Here*/}
else
{/* Do Another Thing Here*/}
}
我很难检查该行是否为最后一行.知道怎么做吗?谢谢.
I have difficulties to check if the row is the last one or not. Any idea how to do it? Thanks.
推荐答案
您可以在while
循环之前使用 mysql_num_rows()
,然后根据您的条件使用该值:
You can use mysql_num_rows()
prior to your while
loop, and then use that value for your condition:
$numResults = mysql_num_rows($result);
$counter = 0
while ($row = mysql_fetch_array($result)) {
if (++$counter == $numResults) {
// last row
} else {
// not last row
}
}
这篇关于PHP检查MySQL最后一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文