php输出字符之间加空格,php – 在HTML表单下拉菜单中从DB连接的两个字符串之间添加空格很困难...

我从同一个表中的2个DB列中提取数据,以

HTML格式填充下拉菜单.虽然我确实获得了两个数据,但我似乎无法用空格分隔它们.下面的代码是我这样做的一般尝试,但我尝试更改和省略空格的引号以及用单引号和双引号括起firstname和lastname.但似乎没有任何效果.到目前为止我离开了:Firstnamelastname.

//db connection

MysqL_connect('localhost','root',"");

MysqL_select_db('recy');

$sql = "SELECT CONCAT(firstname,' ',lastname) FROM technicians";

$result = MysqL_query($sql);

echo "";

while ($row = MysqL_fetch_array($result)) {

echo "" . ucwords($row['CONCAT(firstname,lastname)']) . "";

}

echo "";

?>

任何建议或建议表示赞赏.

CONCAT_WS,是包含分隔符的MysqL函数所以..

$sql = "SELECT CONCAT_WS(' ',firstname,lastname) as name FROM technicians";

然后使用$row [‘name’]

我添加了别名作为名称,使生活更轻松

CONCAT_WS() stands for Concatenate With Separator and is a special form of CONCAT(). The first argument is the separator for the rest of the arguments. The separator is added between the strings to be concatenated. The separator can be a string,as can the rest of the arguments. If the separator is NULL,the result is NULL.

总结

如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值