我有一些列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); ?>
我的解决方案运行良好。
<?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);
?>