在我的数据库的最后一个表行之前回显一个

时间:2017-12-01 05:21:06

标签: php mysqli echo tablerow

这是我的代码,它回显了最后一个表行。我想在最后一个表行之前用这个代码回显一个。任何人都可以帮忙吗?

我用它在我的应用程序中显示表参数

    $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 个答案:

答案 0 :(得分:1)

您可以使用limit获取表格的倒数第二行。

SELECT name,family FROM student_list ORDER BY id DESC LIMIT 1,1