Adding dots(.) after certain characters from mysql response
I have a random mysql response. I need to display the response in smarty template. I want to add dots in one column, but don't know how to do it. Here is my code:
function homepage_profiles()
{
$sql = "
SELECT
*
FROM
tbl_profile
WHERE
bz_pro_show = 'Y'
ORDER BY
RAND()
开发者_Python百科 ";
$res = $this->db->returnArrayOfObject($sql, $pgin = 'no', $odr='no');
return $res;
}
$res_pro = $this->homepage_profiles();
$this->assign_values('rand_pro',$res_pro);
You could either use Smarty with something like {$rand_pro|truncate:50:'...'}
or MySql with something like SELECT CONCAT(LEFT(about_me, 50),"...") as about_me_trunc
...
$var['column'] = substr($var['column'], 0, 50)." ... ";
you can change your sql from select * ...
to select col_a + '.', col_b, col_c ...
.
NB: +
operator is mysql-specific; other database servers use ||
or you can use CONCAT()
to ensure portability.
精彩评论