0

i have this code, and the output is: {"round (avg (salary), 0)":"1750"}

function tableOne() {

    $query = mysql_query("select round (avg (salary), 0) from worker, formation_area where id_formation_area=1") or die(mysql_error());
    $row = mysql_fetch_assoc($query);
    $result = $row;

    echo json_encode($result);
}

tableOne(); 

?>

but i need something like this: {1750}.

Any help?

1
  • 1
    try doing a print_r($result); so you can see the data you're working with. Commented May 18, 2011 at 18:28

1 Answer 1

4

Try this:

function tableOne() {

    $query = mysql_query("select round(avg (salary), 0) as `round_avg` from worker, formation_area where id_formation_area=1") or die(mysql_error());
    $row = mysql_fetch_assoc($query);
    $result = $row['round_avg'];

    echo json_encode($result);
}

tableOne(); 

Remember json needs a something: something_else so you might get an error here since now there is no array being encoded

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.