Forum Moderators: coopster

Message Too Old, No Replies

Save loop output into a variable

Send multiple values from a loop using _POST?

         

Chran

8:47 am on Feb 13, 2007 (gmt 0)

10+ Year Member



I have a page, listing values that are being output from a while loop. I also have a form that the visitor can fill in. When I send the form to the next page I want to grab the result from the while loop into a variable and bring it to the next page using POST. I have tried the following:

while ($row = mysql_fetch_assoc($sqlResult))
{
$tot_query = print_r($row, true);
}

That does not work though. The $tot_query contains only the last value from the loop. How can I save all the values listed from the loop and send them to the next page?

eelixduppy

12:00 pm on Feb 13, 2007 (gmt 0)



I'm not quite sure which page has what on it, but it seems that you either need to be using sessions [us3.php.net], or to query the database on that last page (as well).

Chran

12:05 pm on Feb 13, 2007 (gmt 0)

10+ Year Member



Well, I suppose I will have to query the database, but for that I will need the values from the first page. Those are the unique IDs that I will use in the query so I know where in the database to fetch the data.

omoutop

12:21 pm on Feb 13, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Try something like this...

//
// in first page
//
$tot_ids = "0";
while ($row = mysql_fetch_assoc($sqlResult))
{
$tot_ids = ",".$row['id'];
}
// this will produce a something like $tot_ids = "0,3,6,12,34,56";

//put this into a hidden field in your form
// example: <input name="hidden_ids" type="hidden" value="<? echo $tot_ids;?>">

on the next page...
$ids_check = $_POST['hidden_ids'];
$query = "Select ids FROM {table_name} WHERE ids IN ($ids_check)"

Is this what you are looking for?

Chran

1:15 pm on Feb 13, 2007 (gmt 0)

10+ Year Member



That is exactly what I am looking for, thank you. :)