p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

beginning_php thread: Passing a result set to a PHP page?


Message #1 by "Trey Carroll" <treycarroll@y...> on Wed, 23 Oct 2002 02:32:53
Is it possible to pass a result to a PHP page?  

I've already queried the db and received the result.  

What a *WANT* to do is store the result in a hidden and pass it to the 
page so that I can page within the result w/out having to hit the db every 
time.  

Storing the value in a hidden does NOT work:

**************************************************************
<html><head><title>TEST: Posting a Result</title></head>
<body>
<?php
$token = $_POST['token'];
switch ($token){
	case ($token ==1):
		include("db_def.inc");
		include("db.inc");
		$strSQL = "SELECT * FROM member WHERE user_id like '%a%'";
		$link = db_connect();
		$result = db_retrieve_resultset($strSQL,$link);
	?>
		<form name="form1" action="" method="post">
			<input type="hidden" name="myResultset" value="<?
php echo $result;?>">
			<input type="hidden" name="token" value="2">
			<center><input type="submit"></center>
		</form>
	<?php
	break;
	case ($token ==2):
		$result = $_POST['myResultset'];
		while ($row=mysql_fetch_array($result))
			{
			 echo "User ID: ".$row["user_id"]."<br>";
			}
	break;
}
?>
</body>
</html>
**********************************************

It only produces this:

<html>
<body>
<form name="form1" action="" method="post">
<input type="hidden" name="myResultset" value="Resource id #2">
<input type="hidden" name="token" value="2">
<center><input type="submit"></center>
</form>
</body>
</html>

Which of course gives an error when mysql_fetch_array tries to 
process "Resource id #2".

I cannot use sessions in this situation.  Is there a way to store the 
$result set off as an XML flat file?  Is there a better way?
Message #2 by "Gellings, C.O." <gellingsco@p...> on Wed, 23 Oct 2002 21:28:55 +0200
It's possible the way you want it, but safer for instance is to set a
cookie. The hidden type input tag can be viewed if someone uses 'view
source' from the menu or right mouse click

Carl

-----Original Message-----
From: Trey Carroll [mailto:treycarroll@y...]
Sent: 23 October 2002 02:33
To: beginning php
Subject: [beginning_php] Passing a result set to a PHP page?


Is it possible to pass a result to a PHP page?

I've already queried the db and received the result.

What a *WANT* to do is store the result in a hidden and pass it to the
page so that I can page within the result w/out having to hit the db every
time.

Storing the value in a hidden does NOT work:

**************************************************************
<html><head><title>TEST: Posting a Result</title></head>
<body>
<?php
$token = $_POST['token'];
switch ($token){
	case ($token ==1):
		include("db_def.inc");
		include("db.inc");
		$strSQL = "SELECT * FROM member WHERE user_id like '%a%'";
		$link = db_connect();
		$result = db_retrieve_resultset($strSQL,$link);
	?>
		<form name="form1" action="" method="post">
			<input type="hidden" name="myResultset" value="<?
php echo $result;?>">
			<input type="hidden" name="token" value="2">
			<center><input type="submit"></center>
		</form>
	<?php
	break;
	case ($token ==2):
		$result = $_POST['myResultset'];
		while ($row=mysql_fetch_array($result))
			{
			 echo "User ID: ".$row["user_id"]."<br>";
			}
	break;
}
?>
</body>
</html>
**********************************************

It only produces this:

<html>
<body>
<form name="form1" action="" method="post">
<input type="hidden" name="myResultset" value="Resource id #2">
<input type="hidden" name="token" value="2">
<center><input type="submit"></center>
</form>
</body>
</html>

Which of course gives an error when mysql_fetch_array tries to
process "Resource id #2".

I cannot use sessions in this situation.  Is there a way to store the
$result set off as an XML flat file?  Is there a better way?

Message #3 by "Nikolai Devereaux" <yomama@u...> on Wed, 23 Oct 2002 13:27:49 -0700
Any resource links opened by a PHP script are destroyed by the garbage
collector when your script terminates.

You can't store a db result link identifier in a cookie, session, OR hidden
variable, because it's an invalid value as soon as your script is finished
processing.

If you would like to persist the result values from your db query, then what's
the harm in calling fetch_array() on the first iteration of the script and
persisting those values (via sessions, cookies, hidden form fields)?

nik


  Return to Index