How do I use mb_substr to fetch data?
I can use mb_substr in PHP and get part of string,my problem is I want to
use this function in MySQL and get part of field data, I don't want to use
foreach to get part of that.
I want to use this function in this below code.
subject is 500 char and I want to get 150 char from that and my database
is UTF-8 and my storage engine is MyISAM.
$allContents = $db->loadAssoc( $db->setQuery("SELECT id , subject
FROM contents ;") );
if ( $allContents ){
$data['success'] = true;
$data['message'] = $allContents;
}
else{
$data['success'] = false;
}
I don't like to use this method:
$arr = array();
foreach ( $allContents as $value )
{
$topic['id'] = $value['id'];
$topic['subject'] = mb_substr($value['subject'],0,150,'UTF-8').' ... ';
$arr = $topic ;
}
Can I use substr in MySQL like this code?
No comments:
Post a Comment