PHP Check MySQL Last Row
mysql, php
Solution
You can use `mysqli_num_rows()` prior to your `while` loop, and then use that value for your condition:
$numResults = mysqli_num_rows($result);
$counter = 0
while ($row = mysqli_fetch_array($result)) {
if (++$counter == $numResults) {
// last row
} else {
// not last row
}
}
Problem
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.