我有一些列id
,name
,place
和wish
如何剪切希望
中的文字 <?php
//connect to database
include 'db.php';
$link = mysql_connect("localhost",$db_user,$db_pass);
$db = mysql_select_db($db_name, $link);
mysql_query("set names utf8");
$sth = mysql_query("SELECT * FROM wishes");
$rows = array();
while($r = mysql_fetch_assoc($sth)) {
$rows[] = $r;
}
print json_encode($rows); ?>
答案 0 :(得分:0)
我的解决方案,工作正常。
<?php
//connect to database
include 'db.php';
$link = mysql_connect("localhost",$db_user,$db_pass);
$db = mysql_select_db($db_name, $link);
mysql_query("set names utf8");
$sth = mysql_query("SELECT id, name, place, IF(SUBSTR(wish, 1, 120)=wish, wish, CONCAT(SUBSTR(wish, 1, 120), '...')) wish FROM wishes");
$rows = array();
while($r = mysql_fetch_assoc($sth)) {
$rows[] = $r;
}
print json_encode($rows);
?>