-3

i want to echo an array on json format but without labels, only with values.

i have this backsearch.php

<?php 

    // if the 'term' variable is not sent with the request, exit
    if ( !isset($_REQUEST['term']) )
        exit;

    $data = array();
    $con=mysql_connect("localhost","root","");
    $db=mysql_select_db("Fw.To",$con);
    $rs=mysql_query('select * from Users where Owner LIKE "'. mysql_real_escape_string($_REQUEST['term']) .'%"', $db);
    if ( $rs && mysql_num_rows($rs) )
    {
        while( $row = mysql_fetch_array($rs, MYSQL_ASSOC) )
        {
            array_push($data, $row['Owner']);
        }
    }
    echo json_encode($data);
    flush();

?>

and this javascript-jquery inside on my html where it wait the only value json

<script>
    jQuery(document).ready(function($){
  $('#search').autocomplete({source: 'backsearch.php'});
});
</script>

Any idea?

EDIT: i want to take ["red","blue","yellow"] for give it on javascript and no {"0":red,"1":blue,"3":yellow}

  • I don't understand, that would make invalid JSON code. Can you include an example of the code you want returned? – Twisty Oct 20 '15 at 23:34
  • Desired output will be helpful. And you should start using mysqli insted of mysql. See this question to know why. http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php – Nijraj Gelani Oct 20 '15 at 23:36
  • of course i can... i want to take ["","'bar'","\"baz\"","&blong&","\u00e9"] for give it on javascript and no {"a":1,"b":2,"c":3,"d":4,"e":5} – Ilias Tsoumas Oct 20 '15 at 23:37

2 Answers2

1

You can use php 'array_values':

(PHP 4, PHP 5, PHP 7) array_values — Return all the values of an array

array_values

<?php
echo json_encode(array_values($data));

That should take care of it

Sean
  • 1,304
  • 11
  • 26
  • i want to take ["red","blue","yellow"] for give it on javascript and no {"0":red,"1":blue,"3":yellow}... array_value don't do it this but i thnx for your time – Ilias Tsoumas Oct 20 '15 at 23:47
0

sorry guys,

the problem is there

$rs=mysql_query('select * from Users where Owner LIKE "'. mysql_real_escape_string($_REQUEST['term']) .'%"', $db);

the second arguments $db don't need... i mustn't use msql... i will change and this script with mysqli