Okay PHP people, figure this one out

Discussion in 'OT Technology' started by RyanL, Aug 15, 2005.

  1. RyanL

    RyanL OT Supporter

    Joined:
    Nov 30, 2004
    Messages:
    4,584
    Likes Received:
    0
    Location:
    St. Paul, MN
    I have a form that I am building that uses a variable amount of inputs. Basically I don't know how many catagories there are going to be.

    So I have a series of catagories that have checkboxes. The amount and names are pulled from a mysql database. Right now the form is set up to have something like this:

    Code:
      <input type="hidden" name="num_catagories" value="n" />
       
       <input type="checkbox" name="catagory_1" value="1" />
       <input type="checkbox" name="catagory_2" value="1" />
       ...
       <input type="checkbox" name="catagory_n" value="1" />
    Where n is the number of catagories. Pretty straight forward. Now my problem is when it comes to reading in the variables on the recieveing page. Its not like a I can do a for loop for the variables...

    PHP:
    for ($i 0$i $_POST['num_catagories']; $i++) {
         
    $holder $holder $_POST['catagory_$i'] . ", ";
    }
       
    Now I know that it won't work, but something similar is what I need done. I really don't know what else to do other then having a ton of if/then statements for each and every catagory. That would leave me with 30 or so if statements and when there would only be 3 or 4 catagories it would still have to run through them all.

    So if anyone else has any ideas, please, I'd love to know.
     
  2. CyberBullets

    CyberBullets I reach to the sky, and call out your name. If I c

    Joined:
    Nov 13, 2001
    Messages:
    11,865
    Likes Received:
    0
    Location:
    BC, Canada/Stockholm, Sweden
    why not set them as an array and run through them like that?
     
  3. RyanL

    RyanL OT Supporter

    Joined:
    Nov 30, 2004
    Messages:
    4,584
    Likes Received:
    0
    Location:
    St. Paul, MN
    Yup I'm idiot

    PHP:
       for ($i 0$i $_POST['num_catagories']; $i++) {
            
    $holder $holder $_POST[&quot;catagory_&quot; . &quot;$i&quot;] . &quot;, &quot;;
       }  
       
    That will work, :doh: man I hate Mondays...
     
  4. jrwfz5

    jrwfz5 New Member

    Joined:
    Jul 12, 2004
    Messages:
    60
    Likes Received:
    0
    Location:
    Columbia MO Mizzou Baby
    Looks like someone has a case of the mondays
     

Share This Page