Results 1 to 12 of 12

Thread: get name of field in GET [Resolved]

  1. #1

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945

    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.
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  2. #2

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945
    Nevermind, I got it:

    PHP Code:
    while($curarr each($_GET))
    {
    $curkey $curarr['key'];
    $curval $curarr['value'];;
    echo 
    $curkey;
    echo 
    $curval "<br>"
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.

  4. #4

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945
    yeah... I found out about the list thing after posting that. Thanks
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  5. #5
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    I just gave you the method for doing this in a thread yesterday...
    My evil laugh has a squeak in it.

    kristopherwilson.com

  6. #6

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945
    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 )
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  7. #7
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489
    uhh, whats the advantage of using the whille...wend over using do while...loop?

  8. #8

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945
    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.
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  9. #9
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  10. #10
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.

  11. #11
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.

  12. #12
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    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.
    My evil laugh has a squeak in it.

    kristopherwilson.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width