php-mysql : concat query in below code and manipulation of code

标签 php mysql

这是我的代码

<?php
$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;
$offset = ($page-1)*$rows;
$result = array();

include 'conn.php';

//$rs1 = "select CONCAT(id,' ',firstname) AS password FROM users";

$rs = mysql_query("select count(*) from users");

$row = mysql_fetch_row($rs);


$result["total"] = $row[0];
$rs = mysql_query("select * from users limit $offset,$rows");


$items = array();
while($row = mysql_fetch_object($rs)){
    array_push($items, $row);
}
$result["rows"] = $items;

echo json_encode($result);
?>

我的输出是

ID   firstname     lastname  password*
 1    john          abc 
 2    don           def
 3    man           ghi

我想要使用 id+名字 来取消密码。请帮助我完成上面的代码...

最佳答案

更正的代码:

<?php
$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;
$offset = ($page-1)*$rows;
$result = array();

include 'conn.php';

//$rs1 = "select CONCAT(id,' ',firstname) AS password FROM users";

$rs = mysql_query("select count(*) from users");

$row = mysql_fetch_row($rs);


$result["total"] = $row[0];
$rs = mysql_query("select *, CONCAT(id, firstname, password) AS pwd  from users limit $offset,$rows");


$items = array();
while($row = mysql_fetch_object($rs)){
    array_push($items, $row);
}
$result["rows"] = $items;

echo json_encode($result);

?>

关于php-mysql : concat query in below code and manipulation of code,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19020312/

相关文章:

php - 如何在 php 中强制更改日期时间中的日期

php - 限制分页页码

javascript - 阻止 Ajax 表单发送 "normally"不起作用

mysql - 如果使用 AVG 函数,SQL 查询结果将缩减为单个结果

php - 使用所需类别 ID 和 OR 类别 ID 过滤产品

mysql - Ssequelizejs、MySQL 和 Passportjs user.findOne 不是函数

php - 在 MySQL 中获取每个月的最后一条记录....?

php - 如何将数组转换为字符串

php - 选择前 5 个结果 : PHP/SQL

php - 在Jquery EasyUI中从2个mysql表中选择数据