0

i have mysql database for i fetch information using json for example:

$sql ="SELECT * FROM parent WHERE id = '$name'";       
$result = mysql_query($sql);
while($row = mysql_fetch_array($result))
 {
$abc=$row[id];
}
echo json_encode($abc)

Now how can i display this json encoded element in my main html file using jquery? what i want to do is based on this fetched element i want to do some if else operation.

for example:

if(value of row[id](should be achieved using jquery) ==null)
{}
else
{}

I am looking for something like $(xxxx).somefunction() Thanks in advance.

2 Answers 2

1

You could use jQuery to convert the JSON into a JavaScript object and then add the properties of the object into your html.

jQuery.parseJSON( json )

Add the JSON from the database to your webpage through:

echo "var myJson = ".json_encode($abc);

Then use jQuery to parse the JSON through:

myObject = jQuery.parseJSON(myJson);
alert(myObject.id);
Sign up to request clarification or add additional context in comments.

Comments

1

You can create a javascript var:

echo('var test = ' . json_encode($abc));

Now you can acces the var "test" with javascript.

1 Comment

hey i am looking for something like this $(xxxx).somefunction()

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.