dpr26232 2011-05-25 15:29
浏览 11
已采纳

CakePHP中的虚拟字段上的子串+ Concat - 可能吗?

This seems like a simple question, but I can't get it to work. I've created a virtual field that combines a name and address:

var $virtualFields = array(
    'name_address' => 'CONCAT(Venue.name, " - ", Venue.address)'
);

Is there a way to use SUBSTR on this? (PHP or MYSQL is fine - whichever is best/works).

I've tried this (to no avail):

'name_address' => 'SUBSTR(CONCAT(Venue.name, " - ", Venue.address),0,50)'

I've also tried SUBSTR on the individual fields within the CONCAT.

  • 写回答

1条回答 默认 最新

  • dongyi8416 2011-05-25 19:48
    关注

    This is absolutely no problem. Your only error is, that you thought of the SUBSTRING-function in MySQL working like the one in PHP where the count starts at zero. But since this isn't PHP you have to start your counting from 1 and all will work fine.

    Just use your virtualField like this and it should work just like you want:

    var $virtualFields = array(
        'name_address' => 'SUBSTRING(CONCAT(Venue.name, " - ", Venue.address),1,50)'
    );
    

    Also, have a read on the SUBSTRING-function in the MySQL manual

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了