Was hoping someone could give me some help. I have been trying to learn pagination but have run into an issue. when I run this to get my total rows count:

```
 $sql = "SELECT COUNT (*) FROM item WHERE fid='17'";
 $query = mysqli_query($con, $sql);
 $row = mysqli_fetch_row($query);
 $rows = $row[0];

```

$rows comes back with no value, I am under the impression that $rows should contain the total number of records from item with the fid of 17, when I run `SELECT COUNT (*) FROM item WHERE fid='17'` in phpmyadmin it returns 98 which is the correct count. Directly before the above code I use this code to connect to the db, which I use again later to display the records which works fine.

```
$con=mysqli_connect("$host","$username","$password","$dbname");

// Check connection

if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
} 

```

This statement displays records later in the script

```
$sql = mysqli_query($con,"SELECT * FROM item WHERE fid='17' ORDER BY id DESC $limit ");

```

So there is data and the info is correct.

I have been following this tutorial on the subject <http://www.developphp.com/view.php?tid=1349> and it works like a charm on his example in the video, all I have changed is the database particulars to mine. Can't figure this one out, been stuck for days so now I am bothering you fine folks.

Update: Changed

```
 $query = mysqli_query($con, $sql);
 $row = mysqli_fetch_row($query);
 $rows = $row[0];

```

to

```
if ($result=mysqli_query($con,$sql))
{
// Return the number of rows in result set
$rows=mysqli_num_rows($result);
// Free result set
mysqli_free_result($result);
}

```

And everything is working now. Still wish I knew what was wrong with my original code but I will be moving on. Thanks Phil Perry for all your help this morning!