Php 从mysql json数据中剪切文本
我有一些柱子Php 从mysql json数据中剪切文本,php,mysql,json,Php,Mysql,Json,我有一些柱子id,name,place和wish 如何在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");
id
,name
,place
和wish
如何在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);
?>
请将$rows的输出添加到您的问题中。使用var_dump($rows)可以做到这一点!它的工作但不正确$sth=mysql_query(“从愿望中选择SUBSTR(愿望,1,20”);我有{“SUBSTR(wish,1,20)”:“几乎所有m”},但需要{“wish”:“几乎所有m”},