Mysql table for json

I plan to use jQuery UI Autosuggest for the search form. So I need json output that can be used by jQuery UI Auto.

Here is the database alt text

Table name recent_tags

I tried this

Connect to db first

$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);

but it does not work.

Please help me..

EDIT:

getting an error

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

thank

+3
source share
2 answers

Try the following:

$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);
+6
source

It’s probably not the route that you will go, but I will give this answer for completeness or simply because it is interesting to me:

JSON . mysqludf.org MYSQL JSON . JSON:

select json_array(
   customer_id
   ,first_name
   ,last_name
   ,last_update
   ) as customer
from   customer 
where  customer_id =1;

, .

+3

Source: https://habr.com/ru/post/1771871/


All Articles