Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Pro PHP
|
Pro PHP Advanced PHP coding discussions. Beginning-level questions will be redirected to the Beginning PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 6th, 2005, 10:38 PM
u3 u3 is offline
Registered User
 
Join Date: Apr 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Sending data between 2 computers

I've 2 computers 192.168.1.1(php&mySql) and 192.168.1.2(php&Oracle), I want to send data from one to another, example:

Computer 1:
-----------
index.php (this page will print a result from query in Computer 2)
<?
 ...
 $fromC2 = header("location: http://192.168.1.2/query.php?action=q");
 echo $fromC2; //it won't print anything :(
?>

Computer 2:
-----------
query.php (this page will receive request from Computer 1, running query and send result back to Computer 1)

<?
 ...
 function getQ(){
    $query = "....";
    ....
    //echo $data; //this will print data
    return($data);
 }

 switch($_REQUEST['action'])){
   case 'q' : getQ();break;
   .....
 }
?>

question is:
How can I print the $data(return value from Comp 2) in Computer 1(index.php) ?

thanks
 
Old September 7th, 2005, 04:21 AM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 166
Thanks: 2
Thanked 33 Times in 33 Posts
Default

Hi,

I dont know of a way to actually return the object data to computer1, but you could echo the data in C2 in a structured format like XML, then use the normal IO functions in C1 to read this, similar to how a web service works. Something like this:

/* computer 1 */
$fp = fopen("http://192.168.1.2/query.php?action=q", "r");
$fromC2 = fread($fp, 1024); // remember filesize() doesnt work with urls
fclose($fp);

// parse XML in $fromC2 here
echo $fromC2;

/* computer 2 */
function getQ()
{
  $query = "....";
  // create XML from result set here
  echo $xmldata; // this will print data for C1 to read
}

switch($_REQUEST['action'])
{
  case 'q':
    getQ(); break;
  .....
}

Instead of text/XML you could use some binary format if you wished (just remember to put "rb" in fopen on windows).

Hope this helps
Philip Cole
 
Old September 7th, 2005, 06:34 AM
u3 u3 is offline
Registered User
 
Join Date: Apr 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks philip_cole,

but how about if I'm going to paging the result, because data from comp 2 is quite big, example:

....
$query = "select * from myTable";
$result = mysql_query($query);
$data = mysql_fetch_array($result); //now $data contains many
....

If I print it in comp2, offcourse no big deal I just put
while($rec = mysql_fetch_array($result)){
  echo $rec['myField'];
}

my question is, is it possible to send $data from Comp2, so I can print it in Comp1 (like I print it in Comp2) ?


thanks
 
Old September 15th, 2005, 07:34 PM
Friend of Wrox
 
Join Date: Aug 2004
Posts: 385
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Output the data as either a pdf, or text, then take that file and print it on the other computer??






Similar Threads
Thread Thread Starter Forum Replies Last Post
problem in e-mail structure sending data from data tiawebchd General .NET 3 May 5th, 2008 08:07 AM
XML Editor for Mac Computers muki XML 0 March 13th, 2006 10:28 PM
functions on different computers lizhaskin VB Databases Basics 0 October 13th, 2005 04:39 AM
networked computers? lagalag VB How-To 0 March 23rd, 2004 10:11 AM
How to synchronize time on two computers Vladimirs VB How-To 0 June 29th, 2003 06:55 AM





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