|
-
Jan 13th, 2004, 12:49 PM
#1
Thread Starter
Frenzied Member
get name of field in GET [Resolved]
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...
Last edited by ober0330; Jan 13th, 2004 at 02:30 PM.
-
Jan 13th, 2004, 01:22 PM
#2
Thread Starter
Frenzied Member
Nevermind, I got it:
PHP Code:
while($curarr = each($_GET))
{
$curkey = $curarr['key'];
$curval = $curarr['value'];;
echo $curkey;
echo $curval . "<br>";
-
Jan 13th, 2004, 02:23 PM
#3
Easier:
Code:
while(list($curkey, $curval) = each($_GET))
Even easier:
Code:
foreach($_GET as $curkey => $curval)
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jan 13th, 2004, 02:29 PM
#4
Thread Starter
Frenzied Member
yeah... I found out about the list thing after posting that. Thanks
-
Jan 13th, 2004, 05:14 PM
#5
Stuck in the 80s
I just gave you the method for doing this in a thread yesterday...
-
Jan 14th, 2004, 07:55 AM
#6
Thread Starter
Frenzied Member
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 )
-
Jan 14th, 2004, 09:15 AM
#7
Frenzied Member
uhh, whats the advantage of using the whille...wend over using do while...loop?
-
Jan 14th, 2004, 09:19 AM
#8
Thread Starter
Frenzied Member
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.
-
Jan 14th, 2004, 09:19 AM
#9
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
-
Jan 14th, 2004, 10:54 AM
#10
PHP is more flexible than you people think.
Here's every legal loop construct.
Code:
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.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jan 14th, 2004, 10:55 AM
#11
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.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jan 14th, 2004, 02:13 PM
#12
Stuck in the 80s
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|