Php 通过插入字符串将MySQL数据转换为JSON数组
这是我目前的代码,但它只在Php 通过插入字符串将MySQL数据转换为JSON数组,php,mysql,json,Php,Mysql,Json,这是我目前的代码,但它只在mysqlresultsetotjson()中的for循环之前有效 谢谢大家! 托马斯用户喜欢 $result = $link->query("SELECT * from Ticket"); $rows = array(); while($r = mysqli_fetch_assoc($result)) { $rows[] = $r; } print "<pre>"; print_r(json_encode(array('Results'
mysqlresultsetotjson()
中的for循环之前有效
谢谢大家!
托马斯用户喜欢
$result = $link->query("SELECT * from Ticket");
$rows = array();
while($r = mysqli_fetch_assoc($result)) {
$rows[] = $r;
}
print "<pre>";
print_r(json_encode(array('Results' =>$rows)));
$link->close();
$result=$link->query(“从票据中选择*);
$rows=array();
而($r=mysqli\u fetch\u assoc($result)){
$rows[]=$r;
}
打印“”;
打印(json编码(数组('Results'=>$rows));
$link->close();
echo“mysql数据
”;
$result=$link->query(“从用户中选择*);
打印($result->fetch_object());
回声“
”;
echo“在json中
”;
$res=['Results'=>$result->fetch_object();
echo json_编码($res);
$link->close();
你想把输出作为JSON字符串吗?不,在最后我需要JSON数组来创建所有的JS脚本。请考虑在你的答案和代码片段中添加细节,关于你正在做什么以及为什么要这么做。
$result = $link->query("SELECT * from Ticket");
$rows = array();
while($r = mysqli_fetch_assoc($result)) {
$rows[] = $r;
}
print "<pre>";
print_r(json_encode(array('Results' =>$rows)));
$link->close();
echo "mysql data<br />";
$result = $link->query("SELECT * from users");
print_r($result->fetch_object());
echo "<br />";
echo "in json<br />";
$res = ['Results' => $result->fetch_object() ];
echo json_encode($res);
$link->close();