H. Ferrence
H. Ferrence

Reputation: 8116

How to know if you are on the first record in a PHP/MySQL mysql_fetch_array()

Is there any function or way of telling if the row you are on is the first in the query result from a mysql_fetch_array() ?

I know how to do this with setting a switch variable, but I was just wondering if there is a more streamlined way to do this.

Thanks.

Upvotes: 4

Views: 1112

Answers (3)

dqhendricks
dqhendricks

Reputation: 19251

no, there is not. at least not with the regular mysql_.

Upvotes: 3

dan-lee
dan-lee

Reputation: 14492

You could use mysqli_field_tell() to get the internal pointer of your result set (but only with mysqli* functions).

Upvotes: 0

Gavriel
Gavriel

Reputation: 19237

$i = 0;
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
    if (!$i) {
        echo "1st row";
    }
    $i++;
}

Upvotes: 0

Related Questions