在 PHP 中获取指针位置,同时mysql_fetch_array函数

get pointer position in a php while mysql_fetch_array function

提问人:pedalpete 提问时间:2/7/2009 更新时间:2/7/2009 访问量:2923

问:

我在 php 中有一个相当标准的 while mysql_fetch_array语句,我正在尝试找出结果集中的哪一行正在打印。

我认为这应该很简单,但我已经提出了一个相当标准

$i=0;
$count=mysql_num_rows($getResults);
while($resultArray=mysql_fetch_array($getResults)){

$i++
if($i==$count){
echo "this is the last row";
}
}

但奇怪的是,这行不通。有没有其他方法可以找到最后一行?

php while-循环

评论


答:

1赞 nickf 2/7/2009 #1

你得到的是正确的(也就是说,它应该可以工作):你确定返回的行超过 0 行吗?

评论

0赞 pedalpete 2/7/2009
是的,返回了超过 0 行,但我搞砸了我的循环,所以最后一位在 while 循环之外运行。对不起,我的错。
1赞 Samuel 2/7/2009 #2

这对我有用。您的位置略有不同,并且在 $i++ 之后没有分号

$i=0;
$count=mysql_num_rows($result);
while($resultArray=mysql_fetch_array($result))
{
    if($i==$count-1)
    {
        "this is the last row";
    }
    $i++;
}