0

here is my code

<?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);
?>

and my output is

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

I want password to cancat with id+firstname.. help me in above code please...

1
  • 1
    Dont use mysql_query more.Try PDO Commented Sep 26, 2013 at 5:52

1 Answer 1

2

Corrected Code:

<?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);

?>
Sign up to request clarification or add additional context in comments.

4 Comments

Whenever I see string concats in MySQL, I wish that they would include the || string operation from oracle which makes it so quick to write string concats.
but no change in oputput :/
You need to access $row['pwd'] because, we have used alias.
@ProgrammingStudent i dint get u

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.