PHP & JSON JAVASCRIPT

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
keeran
Forum Newbie
Posts: 3
Joined: Fri Apr 22, 2011 9:17 am

PHP & JSON JAVASCRIPT

Post 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]
fugix
Forum Contributor
Posts: 207
Joined: Fri Mar 18, 2011 8:01 pm

Re: PHP & JSON JAVASCRIPT

Post by fugix »

is the array stored in a database?
keeran
Forum Newbie
Posts: 3
Joined: Fri Apr 22, 2011 9:17 am

Re: PHP & JSON JAVASCRIPT

Post by keeran »

No. php file contain this array
fugix
Forum Contributor
Posts: 207
Joined: Fri Mar 18, 2011 8:01 pm

Re: PHP & JSON JAVASCRIPT

Post 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
keeran
Forum Newbie
Posts: 3
Joined: Fri Apr 22, 2011 9:17 am

Re: PHP & JSON JAVASCRIPT

Post 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
Post Reply