1

我使用 left 语句和 Locate 来获取数据库中某个字段的子字符串来执行(显示更多)。它工作正常,但有时工作不正常。

这是代码:

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 的书不会完全出现。

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

4

0 回答 0