Seek to row number 15 in the result-set in PHP

Description

The following code shows how to seek to row number 15 in the result-set.

Example


// ww  w  . j  a  va2 s. c  om
<?php
     $con=mysqli_connect("localhost","root","","test");
     // Check connection
     if (mysqli_connect_errno()){
         echo "Failed to connect to MySQL: " . mysqli_connect_error();
     }

     $sql="SELECT name FROM employee";

     if ($result=mysqli_query($con,$sql)){
         // Seek to row number 15
         mysqli_data_seek($result,14);

         // Fetch row
         $row=mysqli_fetch_row($result);

         printf ("Lastname: %s Age: %s\n", $row[0], $row[1]);

         // Free result set
         mysqli_free_result($result);
     }

     mysqli_close($con);
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    MySQL »




MySQLi
MySQLi Object Oriented