0

I am trying to use PHP to return tName from the database and then output it in the following way: {"tName":["Name1", "Name2"]}) So far it is returning ["Name1", "Name2", "Name3"] but that is not what I want.

Here is my current code

$q = mysql_query("SELECT tName FROM Template");
$result = array();
while($e=mysql_fetch_array($q, MYSQL_ASSOC)){
$result[]=$e['tName'];
}       
echo json_encode($result);
1
  • 1
    json_encode(array("tName" => $result))? Commented May 2, 2014 at 2:16

1 Answer 1

1

you just need to add the key.

$result['tName'][]=$e['tName'];

or

json_encode(array("tName" => $result))
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.