Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> Php To Java
khalilov
post Sep 1 2008, 11:13 AM
Post #1


Advanced Member
Group Icon

Group: [HOSTED]
Posts: 175
Joined: 17-July 08
From: Atlantis
Member No.: 31,503
myCENTs:58.67



How do you pass a variable from PHP to JAVA?
i tried
CODE
var x= <?php echo $variable; ?>

it doesn't work
Go to the top of the page
 
+Quote Post
Darasen
post Sep 2 2008, 04:18 PM
Post #2


Advanced Member
Group Icon

Group: [HOSTED]
Posts: 175
Joined: 3-April 08
From: Milling about
Member No.: 29,596
myCENTs:60.78



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.
Go to the top of the page
 
+Quote Post
khalilov
post Sep 2 2008, 04:24 PM
Post #3


Advanced Member
Group Icon

Group: [HOSTED]
Posts: 175
Joined: 17-July 08
From: Atlantis
Member No.: 31,503
myCENTs:58.67



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?
Go to the top of the page
 
+Quote Post
pyost
post Sep 2 2008, 06:51 PM
Post #4


Nenad Bozidarevic
Group Icon

Group: [MODERATOR]
Posts: 1,043
Joined: 7-November 05
From: Belgrade, Serbia
Member No.: 9,500
myCENTs:38.31



The code you wrote should work, I'm sure something else is the real problem wink.gif
Go to the top of the page
 
+Quote Post
docduke
post Sep 2 2008, 08:13 PM
Post #5


Advanced Member
Group Icon

Group: [MODERATOR]
Posts: 137
Joined: 8-January 08
Member No.: 27,477
myCENTs:48.54



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! cool.gif
Go to the top of the page
 
+Quote Post
khalilov
post Sep 2 2008, 09:31 PM
Post #6


Advanced Member
Group Icon

Group: [HOSTED]
Posts: 175
Joined: 17-July 08
From: Atlantis
Member No.: 31,503
myCENTs:58.67



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?
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. java.lang.NullPointException(4)
  2. Using system date in java... How?(5)
  3. javascript vs java(12)
  4. Array Sorting(21)
  5. What Are The Advantages Of Java Vs C++?(15)
  6. Java Applets(5)
  7. Python Versus Java ?(4)
  8. A Complete Java Tutorial(4)
  9. Need Help: Find Lowest Character Using Java(7)
  10. Download Java Ebooks(15)
  11. Java By Example(8)
  12. Video Streaming In Web Browser Through Java Or Jsp(1)
  13. Looking For A Java IDE(25)
  14. How To Create Exe File In Java?(13)
  15. How Do I Test A Java Aplication(11)
  1. Counting Down To A Time(7)
  2. Graphcal User Interfaces In Java(4)
  3. Java: Eclipse(4)
  4. Loading 3d Models In Java?(2)
  5. Java Applet Loading Error(5)
  6. Setting Up Java Correctly(8)
  7. Java Java.security.accesscontrolexception(6)
  8. Simple Java Question(3)
  9. Java And Sql: Data Mismatch(6)
  10. Java Memory Leak?(2)
  11. Java Mouse Movement.(2)
  12. How To Validate The Login Form Using Php Pcre(0)
  13. How To Design The Popup Menu Item Using Javascript(1)(0)


 



- Lo-Fi Version Time is now: 22nd November 2008 - 03:32 PM