Page 1 of 1

PHP & JSON JAVASCRIPT

Posted: Fri Apr 22, 2011 9:39 am
by keeran
Hi

test.php

Code: Select all

1,3,5,7
test2.php

Code: Select all

header('Content-type: application/json');

echo json_encode(array(4, 5, 8, 9, 12, 32));

Html file
[text]
<a>odd ,/a>
<a >even</a>
<div id="test"></div>
[/text]

[text]
when user click odd link, need to display 1,3,5,7 & when user click even link 2,4,6 need to display in the idv tag.

Please guide me how to do this part.
[/text]

Re: PHP & JSON JAVASCRIPT

Posted: Fri Apr 22, 2011 9:51 am
by fugix
is the array stored in a database?

Re: PHP & JSON JAVASCRIPT

Posted: Fri Apr 22, 2011 12:27 pm
by keeran
No. php file contain this array

Re: PHP & JSON JAVASCRIPT

Posted: Fri Apr 22, 2011 2:45 pm
by fugix
ok so you could set up two if functions...one for when the even link is clicked and one for whan the odd link is clicked...then inside of each of the if functions...you can add a foreach loop, which will allow you to pull out certain values from your array. then all you have to do is tell it which values to display when each link is clicked...any questions let me know

Re: PHP & JSON JAVASCRIPT

Posted: Fri Apr 22, 2011 11:55 pm
by keeran
Hi;

I am new to PHP & JAVASCRIPT . I dont know how to get the json result in javascript. One file is encoded, other one is not encoded. so how to get the result in script. please can u example through coding?

Thank you