1

this is my code that echo last table row . and i wanna echo one before the last table row together with this code . any body can help ?

i use this to show table parameters in my application

    $conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
   //Checking if any error occured while connecting
 if (mysqli_connect_errno()) {
 echo "Failed to connect to MySQL: " . mysqli_connect_error();
die();
}
//creating a query
$stmt = $conn->prepare("SELECT name,family FROM student_list;");

//executing the query 
$stmt->execute();

//binding results to the query 
$stmt->bind_result(

$t1,
$t2

);
 $list = array(); 

 //traversing through all the result 
 while($stmt->fetch()){
 $temp = array();

$temp['t1'] = $t1;
$temp['t2'] = $t2;

array_push($list, $temp);
}

//displaying the result in json format 
 echo json_encode($list);

1 Answers1

1

You can use limit to get second last row of table.

SELECT name,family FROM student_list ORDER BY id DESC LIMIT 1,1
urfusion
  • 5,528
  • 5
  • 50
  • 87