gpt4 book ai didi

php - mysql表转json

转载 作者:可可西里 更新时间:2023-11-01 00:11:26 24 4
gpt4 key购买 nike

我计划将 jQuery UI Autosuggest 用于搜索表单。所以我需要一个 json 输出,它可以被 jQuery UI Auto suggest 使用。

这是数据库 alt text

表名recent_tags

我试过了

先连接数据库

$do = mysql_query("SELECT * FROM recent_tags where query like '%" . $_GET['query'] . "%'"); 

while ($row = mysql_fetch_array($fetch, MYSQL_ASSOC)) {
$row_array['query'] = $row['query'];
array_push($return_arr,$row_array);
}

echo json_encode($return_arr);

但它不起作用..

请指导我..

编辑:

获取错误

Warning: array_push() [function.array-push]: First argument should be an array in /pathto/my/file.php

谢谢

最佳答案

试试这个:

$return_arr = Array();

$query = mysql_real_escape_string($_GET['query']);
$result = mysql_query("SELECT * FROM recent_tags where query like '%" . $query . "%'");

while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
array_push($return_arr,$row);
}

echo json_encode($return_arr);

关于php - mysql表转json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4040307/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com