left语句在mysql中无法正常工作

时间:2013-07-28 08:32:28

标签: mysql string locate

我使用左语句和Locate来取数据库中某些字段的fet子字符串来做(显示更多)。它工作正常,但有时它无法正常工作。

这是代码:

function split_field($table = "d_book", $field = "bo_about", $length = 195) {
            $tbl_field = "TRIM(".$table.".".$field.")";       
            $sql = "CONCAT(LEFT({$tbl_field}, IF(LENGTH({$tbl_field}) > {$length}, LOCATE(' ', {$tbl_field}, {$length}), {$length})), 
                           IF(LENGTH({$tbl_field}) > {$length}, '...', ''))
                    AS `{$field}`";

            return $sql;

    }

$sql = "SELECT `bo_price`,`bo_id`, `bo_au_id`,`bo_name`,";
$sql .= split_field();
$sql .=",`bo_cover_img`, `bo_num_pages`, `d_book`.`bo_sec_id`, `d_section`.`sec_id`,         `d_author`.`au_id`, `d_author`.`au_name`        
                FROM (`d_book`) 
                JOIN `d_section` ON `d_section`.`sec_id`=`d_book`.`bo_sec_id` 
                JOIN `d_author` ON `d_author`.`au_id`=`d_book`.`bo_au_id` 
                WHERE `d_book`.`bo_state` = '1'";
$sql .= " ORDER BY `d_book`.`bo_ord` DESC LIMIT $start_limit,20";

问题在于,一些字符串少于195的书籍并不完全出现。

提示:所有阿拉伯语字符串

0 个答案:

没有答案