Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Java and JDK > Java Basics
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Java Basics General beginning Java language questions that don't fit in one of the more specific forums. Please specify what version.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 14th, 2006, 06:40 AM
MP3 MP3 is offline
Registered User
 
Join Date: Jul 2006
Location: uae, ad, United Arab Emirates.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default [How] Using java to get a result from a php file?

first of all, i'm sorry if its in the wrong forum

i created a sample php file contain the following code:

Code:
<?php 

require_once('./global.php'); 

$a = $db->query_first("SELECT bb FROM " . TABLE_PREFIX . "aa WHERE `id`='1'"); 


if ("$a"=="3") 
{ 
        $play = "<embed src=\"anything.wav\" autostart=true hidden=true></embed>"; 
} 
else 
{ 
        $play=""; 
} 
?>
Now, i want to create a java code (AJAX) to check the php file every 5 min. when there is a result then a small popup will show to the visitor.

Can anybody help me with the JAVA code?

Many thanks to whoever can assist.

(@)
Reply With Quote
  #2 (permalink)  
Old July 14th, 2006, 07:21 PM
Friend of Wrox
 
Join Date: Jan 2006
Location: San Francisco, CA, USA.
Posts: 198
Thanks: 0
Thanked 0 Times in 0 Posts
Default

BTW there's a huge difference between Java and Javascript. The "J" in AJAX stands for Javascript. Java is primarily used on the server-side, much the same way PHP is used.

As for your answer, look at the Javascript setInterval() function. Here's an example that flips through a slide show every 5 seconds: http://www.devshed.com/c/a/JavaScrip...-JavaScript/5/

You can use basically the same code to do what you're asking. Just change the interval time from 5000 (5 seconds) to "5000*60" (5 minutes). Then in the slideShow() method, which you should rename, call window.open() to create your pop-up. There's lots of web sites out there that explain window.open() -- you should be able to figure it out very fast!!

Good luck!

Jon Emerson
http://www.digg.com/users/panaceaa/profile
Reply With Quote
  #3 (permalink)  
Old July 15th, 2006, 04:20 AM
MP3 MP3 is offline
Registered User
 
Join Date: Jul 2006
Location: uae, ad, United Arab Emirates.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You are right about J = JavaScript.
I'm civil Engineer and I don’t know a lot about using JavaScript and for that reason I asked in this forum.

Okay, I saw the code at the link you posted above, but for instance if there was no result the popup will show and what's the benefit?

I want a function that will check the PHP file if the variable "$a" equal to 3 then the popup will show with the sound "anything.wav", else nothing will happen and the popup will not show.

Can you please give me a help about this because really I spent in this code 1 month trying and trying without any result.


(@)
Reply With Quote
  #4 (permalink)  
Old July 16th, 2006, 03:14 PM
Friend of Wrox
 
Join Date: Jan 2006
Location: San Francisco, CA, USA.
Posts: 198
Thanks: 0
Thanked 0 Times in 0 Posts
Default

What's the point of the pop-up? Is it just to play the sound, or is there some UI you would like to show in it too? Would you prefer the sound to just play from the parent window, if possible?

Jon Emerson
http://www.digg.com/users/panaceaa/profile
Reply With Quote
  #5 (permalink)  
Old July 16th, 2006, 03:47 PM
MP3 MP3 is offline
Registered User
 
Join Date: Jul 2006
Location: uae, ad, United Arab Emirates.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you a lot for your reply
When the variable $a = 3, a popup window will show and the sound will play inside this popup with the ability of stopping this sound or play it again. Also, a text will show inside this popup window say the variable a = $a (where $a will get it from the php file and equal 3)

Okay, why I chose a popup? Because some visitors maybe they muted them speakers and they can't hear the sound, so they will see the popup and they will know there is a sound.



(@)
Reply With Quote
  #6 (permalink)  
Old July 16th, 2006, 04:24 PM
Friend of Wrox
 
Join Date: Jan 2006
Location: San Francisco, CA, USA.
Posts: 198
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hmm, I believe the only way to open the pop-up conditionally is to use XMLHttpRequest to fetch the conditional from the server, and if it's true, then open the pop-up. XMLHttpRequest allows you to make an asynchronous request -- when the response is received, an event is called with the response body stored in the event object. You can parse this response with an XML parser, or simply treat it as a true/false string.

I'm explaining this pretty poorly, but there's more information here:

http://developer.apple.com/internet/...mlhttpreq.html

:)

Jon Emerson
http://www.digg.com/users/panaceaa/profile
Reply With Quote
  #7 (permalink)  
Old July 17th, 2006, 12:54 PM
MP3 MP3 is offline
Registered User
 
Join Date: Jul 2006
Location: uae, ad, United Arab Emirates.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i added this code to my forum header and its didnt work:

Code:
<script language="JavaScript">

function loadXMLDoc(url) {
        req = false;
    // branch for native XMLHttpRequest object
    if(window.XMLHttpRequest) {
            try {
                        req = new XMLHttpRequest();
        } catch(e) {
                        req = false;
        }
    // branch for IE/Windows ActiveX version
    } else if(window.ActiveXObject) {
               try {
                req = new ActiveXObject("Msxml2.XMLHTTP");
              } catch(e) {
                try {
                          req = new ActiveXObject("Microsoft.XMLHTTP");
                } catch(e) {
                          req = false;
                }
                }
    }
        if(req) {
                req.onreadystatechange = processReqChange;
                req.open("GET", mp3.php, true);
                req.send("");
        }
}



function processReqChange() {
    // only if req shows "loaded"
    if (req.readyState == 4) {
        // only if "OK"
        if (req.status == 200) {
           alert("There was a problem retrieving the XML data:\n" +
                req.statusText);
        } else {
            alert("There was a problem retrieving the XML data:\n" +
                req.statusText);
        }
    }
}
</script>
no Alret show in the two case!!

where is the problem?

(@)
Reply With Quote
  #8 (permalink)  
Old July 17th, 2006, 06:38 PM
Friend of Wrox
 
Join Date: Jan 2006
Location: San Francisco, CA, USA.
Posts: 198
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Are you calling loadXMLDoc(url) with a setInterval? Also, you don't need a url parameter in that function if you're hardcoding the location inside the function. Thirdly, req.open("GET", mp3.php, true); should be req.open("GET", "mp3.php", true);, or similar.

Jon Emerson
http://www.jonemerson.net/
Reply With Quote
  #9 (permalink)  
Old July 24th, 2006, 05:01 PM
MP3 MP3 is offline
Registered User
 
Join Date: Jul 2006
Location: uae, ad, United Arab Emirates.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks panacea for your great help. Every thing working fine except the last point, showing the result.
For these lines:

if (req.readyState == 4) {
        // only if "OK"
        if (req.status == 200) {
           alert("There was a problem retrieving the XML data:\n" +
                req.statusText);

Instead of :


           alert("There was a problem retrieving the XML data:\n" +
                req.statusText);


What can I write to show the result?
The result from the php file is:

echo" <SCRIPT>
window.open('mp3.php?do=play','','width=400,height =250,resizable=0,status=0,scrollbars=0,left=450,to p=450');
    </SCRIPT>";

Regards



(@)
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
From .NET to PHP or JAVA redafarhat General .NET 1 April 23rd, 2008 12:36 PM
saving query result to xml file p2pMember SQL Server 2005 0 January 15th, 2008 03:37 AM
distorted result while calling a html file taraprasad Pro JSP 1 January 11th, 2008 04:06 AM
Article on Java and PHP interoperability ypomonh J2EE 0 August 2nd, 2007 05:28 PM



All times are GMT -4. The time now is 11:22 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.