如何使用php向MySQL添加行号列?

时间:2019-06-15 17:43:01

标签: php mysql mysqli

我想添加一个行数计数列,但我的查询在phpmyadmin控制台中有效,但是当我尝试使用“ mysqli_query()”与php一起运行时,它不起作用。

前端错误: Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in" at front end.

后端错误: cannot calculate position of := within +1 AS '#', username, center_id, machine_id, created_on FROM users LIMIT 0,25;

我的查询:

SET @rn = 0; SELECT @rn:=@rn+1 AS '#', username, center_id, machine_id, created_on FROM users LIMIT 0,25;

我的php代码:

$sql = "SET @rn = 0; SELECT @rn:=@rn+1 AS '#', username, center_id, machine_id, created_on FROM users LIMIT $offset, $no_of_records_per_page";
$res_data = mysqli_query($con,$sql);
if(mysqli_num_rows($res_data)>0)
{
    while ($row = mysqli_fetch_assoc($res_data)) 
    {
        **HTML Table code**
    }
}

0 个答案:

没有答案