|
|
|
| Web Hosting |
![]() ![]() |
Php To Java |
Sep 1 2008, 11:13 AM
Post
#1
|
|
|
Premium Member Group: [HOSTED] Posts: 255 Joined: 17-July 08 From: Atlantis Member No.: 31,503 myCENTs:73.77 |
How do you pass a variable from PHP to JAVA?
i tried CODE var x= <?php echo $variable; ?> it doesn't work |
|
|
|
Sep 2 2008, 04:18 PM
Post
#2
|
|
|
Advanced Member Group: [HOSTED] Posts: 195 Joined: 3-April 08 From: Milling about Member No.: 29,596 myCENTs:4.72 |
You are going to have a problem with this, obviously, given that PHP and JAVA are running on two different computers. Remeber that PHP is running on the web server and by the time a web page starts loading on the local client (or web site visitor) machine PHP is already done and no longer executing. Then once the page is loaded for the visitor any Java script or Java applet can run.
Thus the best method for the two to share data seems to be the web page and/or the HTML created by PHP. Perhaps trying to have a form element (hidden if you wish) with a value written in by the PHP and then once the Java starts to execute have Java read that value into a variable. There may be other ways as well but this is off the top my head and sems to be a fairly simple solution. |
|
|
|
Sep 2 2008, 04:24 PM
Post
#3
|
|
|
Premium Member Group: [HOSTED] Posts: 255 Joined: 17-July 08 From: Atlantis Member No.: 31,503 myCENTs:73.77 |
Hmm... what i want to pass is a number form database, lets say i got this number and its $x, how do i pass it?
|
|
|
|
Sep 2 2008, 06:51 PM
Post
#4
|
|
|
Nenad Bozidarevic Group: [MODERATOR] Posts: 1,053 Joined: 7-November 05 From: Belgrade, Serbia Member No.: 9,500 myCENTs:36.94 |
The code you wrote should work, I'm sure something else is the real problem
|
|
|
|
Sep 2 2008, 08:13 PM
Post
#5
|
|
|
Advanced Member Group: [MODERATOR] Posts: 144 Joined: 8-January 08 Member No.: 27,477 myCENTs:34.82 |
Do "View | Page Source" in your browser, and see what actually arrived in the web page. If $variable had the value 5 in the database accessed by the PHP script, the page source should have var x=5 when it arrives in your browser.
If it does not, then you can localize the cause. For example, if the <?php string is still there, you aren't executing the PHP. If the 5 is there but the browser-side result isn't what you want, then you may be generating a web page with a syntax error, such as a missing semicolon. If necessary, add some print statements in the PHP that generate plain HTML, so you can debug what is actually happening, as opposed to what you intended. Computers have the bad habit of doing what you tell them to do, not what you want them to do! |
|
|
|
Sep 2 2008, 09:31 PM
Post
#6
|
|
|
Premium Member Group: [HOSTED] Posts: 255 Joined: 17-July 08 From: Atlantis Member No.: 31,503 myCENTs:73.77 |
Hmm.. i figured out part of the problem
CODE <html><body> <script type="text/javascript"> <?php $string="5"; echo "var my_var ='".$string."'"; // I should have added the "'" for some reason ?> document.write(my_var) </script> </body> </html> However when i put this: CODE <html><body> <script type="text/javascript"> <?php $x=5; echo "var x='".$x."'"; $string="5"; echo "var my_var ='".$string."'"; ?> document.write(x) document.write(my_var) </script> </body> </html> It seems when i start operating with two variables, nothing shows. Page source CODE <html><body> <script type="text/javascript"> var x='5'<br>var my_var ='5'document.write(x) document.write(my_var) </script> </body> </html> I only need to pass one variable atm, but in the future i might need to pass out more, anyone can tell me why having more than one variable causes issues? |
|
|
|
![]() ![]() |
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:
Similar Topics
| Topic Title | Replies | Topic Starter | Views | Last Action | |||
|---|---|---|---|---|---|---|---|
![]() |
1 | Anil Rao | 640 | 3rd December 2008 - 07:57 PM Last post by: iG-benitoo |
|||
![]() |
2 | sparkx | 408 | 12th November 2008 - 12:06 AM Last post by: xboxrulz |
|||
![]() |
15 | mahender | 5,266 | 29th October 2008 - 04:15 AM Last post by: Guest |
|||
![]() |
2 | sparkx | 524 | 24th September 2008 - 11:25 PM Last post by: sparkx |
|||
![]() |
5 | FearfullyMade | 1,642 | 17th September 2008 - 08:58 PM Last post by: Siddharth0016 |
|||
![]() |
13 | vicky99 | 3,098 | 6th September 2008 - 07:52 AM Last post by: Guest |
|||
![]() |
5 | suicide | 2,763 | 5th September 2008 - 08:28 PM Last post by: Guest |
|||
![]() |
7 | cyph3r | 1,532 | 27th August 2008 - 02:17 PM Last post by: Guest |
|||
![]() |
3 | sparkx | 357 | 25th August 2008 - 06:02 AM Last post by: magiccode9 |
|||
![]() |
25 | Hercco | 2,932 | 24th August 2008 - 07:30 AM Last post by: shotgun |
|||
![]() |
8 | snutz411 | 1,630 | 8th August 2008 - 12:53 PM Last post by: Guest |
|||
![]() |
5 | LuPPy | 972 | 22nd July 2008 - 11:37 AM Last post by: Guest |
|||
![]() |
15 | silverkirfsco | 3,070 | 10th July 2008 - 03:47 PM Last post by: iGuest |
|||
![]() |
4 | sparkx | 542 | 17th June 2008 - 06:40 AM Last post by: miCRoSCoPiC^eaRthLinG |
|||
![]() |
6 | sparkx | 594 | 13th June 2008 - 05:42 PM Last post by: yordan |
|||
|
Lo-Fi Version | Time is now: 8th January 2009 - 01:07 AM |
© 2009 AstaHost: Free Web Hosting & Technical Discussion, Free Web Hosting. a member of xisto.
Powered by Invision Board. Skin: IPB Forum Skins
Expand / Collapse Navigation



Sep 1 2008, 11:13 AM





