前导0不显示在mysql表结果中

时间:2016-10-21 11:28:53

标签: php mysql

将两个值连接到mysql表中的一列。来自mysql表的第一个值和来自PHP常量的第二个值保存为define('ACCOUNTCODESUFFIX','016');

MySql查询有点像

SELECT CONCAT_WS(\' \', mbrs.firstname, mbrs.lastname) AS fullname, 
       CONCAT_WS(\'-\',gl.code, '.ACCOUNTCODESUFFIX.') AS code 
FROM allTbls 
    INNER JOIN generalledgertbl gl ON (allTbls.claim_type=gl.claimtype 
                                AND allTbls.claim_category=gl.claimtitle 
                                AND allTbls.claimoption=gl.claimoption)

输出:

fullname |  code

name1 | 12345-16

name2 | 23456-16
  

如何在不使用LPAD()

的情况下输出
fullname |  code

name1 | 12345-016

name2 | 23456-016

1 个答案:

答案 0 :(得分:1)

这样就可以了,没有那些可能导致混淆的逃避

define('ACCOUNTCODESUFFIX','016');

$sql = "SELECT CONCAT_WS(' ', mbrs.firstname, mbrs.lastname) AS fullname, 
       CONCAT_WS('-',gl.code, '" . ACCOUNTCODESUFFIX . "') AS code 
        FROM allTbls 
            INNER JOIN generalledgertbl gl ON (allTbls.claim_type=gl.claimtype 
                                AND allTbls.claim_category=gl.claimtitle 
                                AND allTbls.claimoption=gl.claimoption)";

echo $sql;

结果:

SELECT CONCAT_WS(' ', mbrs.firstname, mbrs.lastname) AS fullname, 
       CONCAT_WS('-',gl.code, '016') AS code 
        FROM allTbls 
            INNER JOIN generalledgertbl gl ON (allTbls.claim_type=gl.claimtype 
                                AND allTbls.claim_category=gl.claimtitle 
                                AND allTbls.claimoption=gl.claimoption)