FW: [PHP-DB] Variable Variables in PHP
| From: | Jonathan Hilgeman | Date: | Thu, 28 Jun 2001 18:45:38 +0000 |
| Subject: | FW: [PHP-DB] Variable Variables in PHP | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-9955@lists.php.net to get a copy of this message | ||
Below is my reply to Morgan the other day.
-----Original Message-----
From: Jonathan Hilgeman
Sent: Wednesday, June 27, 2001 8:36 AM
To: 'Morgan Tocker'
Cc: 'php-db@lists.php.net'
Subject: RE: [PHP-DB] Variable Variables in PHP
Try changing your inputs to:
PRINT "<INPUT type='text' name='name_array[$id]'
value='$name'>";
PRINT "<INPUT type='text' name='email_array[$id]'
value='$email'><BR>";
On the following page after the form is submitted, PHP will create 2 new
arrays, $name_array and $email_array. From there, you can do a foreach on
the arrays:
foreach($name_array as $id => $name)
{
print "My name is $name and my e-mail is " . $email_array[$id] .
"<BR>";
}
- Jonathan
-----Original Message-----
From: Morgan Tocker [mailto:morgan.tocker@choiceconnect.com.au]
Sent: Tuesday, June 26, 2001 7:04 PM
To: php-db@lists.php.net
Subject: [PHP-DB] Variable Variables in PHP
I am having trouble with variable variables;
I want to create a form as follows :-
<?
$result = mysql_query("SELECT * FROM name_and_email");
$num = mysql_numrows("$result");
if ($num!="0") {
$i = 0;
PRINT "<FORM action='test.php'>";
WHILE ($i < $num) {
$name = mysql_result($result,$i,name);
$email = mysql_result($result,$i,email);
$id = mysql_result($result,$i,id);
PRINT "<INPUT type='text' name='name$id'
value='$name'>";
PRINT "<INPUT type='text' name='email$id'
value='$email'><BR>";
$i++;
}
PRINT "<INPUT type='submit'></FORM>";
}
?>
## THIS SHOULD SUBMIT SOMETHING LIKE THIS >>>>
test.php?name1=avalue&email1=avalueagain&name2=secondname&email2=secondemail
THE PROBLEM:
From PHP with variable variables, how do I change $name1 and $email1 into -
## for all $name.$x values do this......
$sql = "UPDATE name_and_email SET name = '$name1', email = '$email1' WHERE
id = '$id'";
Many thanks if someone can help,
Morgan Tocker.
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net
For additional commands, e-mail: php-db-help@lists.php.net
To contact the list administrators, e-mail: php-list-admin@lists.php.net