Page 1 of 1

Trouble displaying varibles from a form.....

Posted: Sat Mar 18, 2006 10:49 pm
by civic3x98
feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I have a form with this piece of code.

PAGE1:

Code: Select all

<?php
for ($x = 0; $x < $ingrediants; $x++)
{
    echo "Qty: <INPUT TYPE='text' NAME='qty".$x."' size='5'>  ";
    myfunction($x);
    echo "Items: <INPUT TYPE='text' NAME=items".$x."'><br>";
}
 
function myfunction($x)
{
    $Sql_statement = "Select field From table";
    $Query = Mysql_query($Sql_statement); 
    If (!$Query) {
        Die('Invalid Query: ' . Mysql_error());
    }

    echo "<SELECT NAME='name".$x."'>";
    While ($Row = Mysql_fetch_assoc($Query)) {
        echo "<option value='" . $types = $Row['field'] . "'>" . $types = $Row['field'];
    }
    echo "</SELECT>";
}
?>

I have an include page (in the PAGE2) which gets all my data from the form

Code: Select all

session_start();
$ArrayList = array("_GET", "_POST", "_SESSION", "_COOKIE", "_SERVER");
foreach($ArrayList as $gblArray)
{
   $keys = array_keys($$gblArray);
   foreach($keys as $key)
   {
       $$key = trim(${$gblArray}[$key]);
	   
   }
}
PAGE2

I am trying to display the data from PAGE1 on PAGE2

Code: Select all

<?php 
	
for ($x = 0; $x < $ingrediants; $x++)
{
    echo "QTY: ".$field.$x"<br>";
}
?>
The problem is, $field has no data in it. So all that outputs is the value of $x. Any ideas of how to display the data?


feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Sat Mar 18, 2006 11:04 pm
by feyd
Neither of the variables you in the last part (ignoring $x) would appear to exist.

Posted: Sat Mar 18, 2006 11:17 pm
by civic3x98
Well originally in was trying to do this:

$qty = "qty".$x

but that obviously doesnt work.

How do I get this variable name?

Posted: Sat Mar 18, 2006 11:34 pm
by feyd
You've already got variable variables in use. That's what you'll need here too.

Posted: Sun Mar 19, 2006 1:46 am
by civic3x98
The variables I need to use are l;ike $qty0 , $qty1 and others like that. my peoblem is getting those. I have to use a loop to increment them. I dont know how many there might be from the pervous page. There could be 1 or there could be 100.

How else do you get $qty0 and $qty1 without a loop?

Code: Select all

for ($x = 0; $x < $ingrediants; $x++)
		{
			echo "QTY: ".$qty.$x"<br>";
					}

Posted: Sun Mar 19, 2006 1:54 am
by feyd
I guess you need to read more on how variable variables work.

http://php.net/language.variables.variable

Posted: Sun Mar 19, 2006 9:32 am
by civic3x98
Thanks! After reading that and trying a few things I got it to work. Here was my solution if anyone comes across this
for ($x = 0; $x < $items; $x++)
{
$qty = "qty";
echo "QTY: ".${$qty.$x}."<br>";
}