Click to See Complete Forum and Search --> : get name of field in GET [Resolved]
ober0330
Jan 13th, 2004, 11:49 AM
I'm submitting a form, and the textboxes located on that form are grabbed from a DB, therefore they are not going to be a designated name, necessarily.
So when I go to update these fields in the DB, can I grab the name of the textbox (which corresponds to the field in the DB) out of the GET array?
I hope that makes sense... :(
ober0330
Jan 13th, 2004, 12:22 PM
Nevermind, I got it:
while($curarr = each($_GET))
{
$curkey = $curarr['key'];
$curval = $curarr['value'];;
echo $curkey;
echo $curval . "<br>";
CornedBee
Jan 13th, 2004, 01:23 PM
Easier:
while(list($curkey, $curval) = each($_GET))
Even easier:
foreach($_GET as $curkey => $curval)
ober0330
Jan 13th, 2004, 01:29 PM
yeah... I found out about the list thing after posting that. Thanks :)
The Hobo
Jan 13th, 2004, 04:14 PM
I just gave you the method for doing this in a thread yesterday...
ober0330
Jan 14th, 2004, 06:55 AM
umm... yeah. You did. I guess that wasn't exactly what I was looking for... but now that I go back and look at that, that's where I was heading. Sorry for the double post.
I'm new at PHP and I'm still getting a handle on it (hence the barrage of n00bie questions :()
Andy
Jan 14th, 2004, 08:15 AM
uhh, whats the advantage of using the whille...wend over using do while...loop?
ober0330
Jan 14th, 2004, 08:19 AM
First of all, this is PHP which is based off of C so you don't have "wend" or "loop".
The advantage of using a While instead of a Do While is that this checks to see if anything has actually been passed from the form.
techgnome
Jan 14th, 2004, 08:19 AM
Originally posted by thephantom
uhh, whats the advantage of using the whille...wend over using do while...loop?
There is no while...wend or do while...loop in PHP. The two options in this case are foreach(...) or while(...). As for which is an advantage over the other... <shrug /> It's just a matter of coding style I think.
TG
CornedBee
Jan 14th, 2004, 09:54 AM
PHP is more flexible than you people think.
Here's every legal loop construct.
while(cond) {
statements
}
while(cond):
statements
endwhile;
do {
statements
} while(cond);
for(init; cond; expr) {
statements
}
for(init; cond; expr):
statements
endfor;
// Only PHP 4+
foreach(array as [key =>] value) {
statements
}
Note: for do...while and foreach loops the : syntax is not mentioned in the reference. It might still work.
CornedBee
Jan 14th, 2004, 09:55 AM
Originally posted by techgnome
It's just a matter of coding style I think.
foreach is shorter and more readable. It only exists since PHP 4, which is why the other syntax is known.
The Hobo
Jan 14th, 2004, 01:13 PM
Originally posted by CornedBee
foreach is shorter and more readable. It only exists since PHP 4, which is why the other syntax is known.
I think the foreach syntax is also easier to understand and see what's going on. I think if someone was new, the whol list() thing would confuse them more than the foreach() would.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.