gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 11:13:14 39 4
gpt4 key购买 nike

只是将两个值连接到 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

How to have Output like this without using LPAD()

fullname |  code

name1 | 12345-016

name2 | 23456-016

最佳答案

这样就可以了,并且不需要所有可能导致困惑的转义

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)

关于php - 前导 0 不显示在 mysql 表结果中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40175548/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com