2013-09-26 39 views
0

CONCAT查詢是我的代碼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 +姓名cancat。 。請幫我在上面的代碼請...

+1

不要使用mysql_query more.Try PDO –

回答

2

更正後代碼:

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

?> 
+0

每當我在MySQL中看到字符串連接時,我希望它們包含來自oracle的'||'字符串操作,這使得它能夠快速寫入字符串連接。 – Fluffeh

+0

@ MR.alien thanx回覆 –

+0

但oputput沒有變化:/ –