User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 455,991 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,771 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 1489 | Replies: 3
Reply
Join Date: Aug 2007
Posts: 10
Reputation: ruman_eee is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 1
ruman_eee ruman_eee is offline Offline
Newbie Poster

get data from php

  #1  
Dec 5th, 2007
hi everyone,
I am in problem to get the array data from php to use it in js.


$data[0]=88;
$data[3]=44;
$data[4]=2232;

I want to use those data in js.


Can anyone help me ??
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 240
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: get data from php

  #2  
Dec 5th, 2007
  1. <?php
  2. $data[0]=88;
  3. $data[3]=44;
  4. $data[4]=2232;
  5. echo "
  6. <html>
  7. <head>
  8. <script type=\"text/javascript\">
  9. function test(){
  10.  
  11. alert('$data[0]');
  12. }
  13. </script>
  14. </head>
  15. <body onload=\"javascript: test();\">
  16. </body>
  17. </html>";
  18. ?>
This is how you can use php variables in your javascript. This is just an example.
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: Aug 2007
Posts: 10
Reputation: ruman_eee is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 1
ruman_eee ruman_eee is offline Offline
Newbie Poster

Re: get data from php

  #3  
Dec 8th, 2007
thank you for your helping,but I need to first check the data ,If data exists then run the js code otherwise not.
this like:
first : read data from database .
second : check the data
third : if data exists then run js otherwise not.

i do it in the same file.but I want to simplify my code ,so I need to place the js code in the other file.
i just need if their have any possibility to get the array data of php in js.
Reply With Quote  
Join Date: Dec 2007
Location: Russia
Posts: 11
Reputation: adorosh is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
adorosh adorosh is offline Offline
Newbie Poster

Re: get data from php

  #4  
Dec 8th, 2007
You can get the JS script into some other file, but make this script use some global variable.
By this way you can parse needed array in PHP, then put the value on page and if the JS script included will find those, it will run.
It's hard code, but will work.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb JavaScript / DHTML / AJAX Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 9:35 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC