Results 1 to 3 of 3

Thread: [Resolved]GET to Array

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2005
    Posts
    103

    Resolved [Resolved]GET to Array

    I have a form with several Textboxes, I send this form to another page using get.

    Is it possible to get the values of the form into an array.

    PHP Code:
    <form method=get action=next.php>
    <table border = 0>
    <?
             for($i=1; $i<=$anzahl; $i++){
            echo ("<tr>");
            for($z = 0; $z <= $anzahl; $z++){
                echo ("<td> <input type=Text name=test value=0 size=3                 maxlength=4> </td>");    
            }
            echo ("</tr>");    
        }
    ?>
        </table>
    <input type=Submit name=aktion value=Rechnen>
    </form>
    The problem is that the array should be two dimensional and that the size depens on $anzahl.
    I thought of doing something like
    PHP Code:
    <input type=Text name=test$i$z value=0 size=3 maxlength=4
    but i hope that there's an easier way. Plz help!!

    FES Germany
    Last edited by FES Germany; Apr 7th, 2006 at 02:13 PM.

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: GET to Array

    You can have PHP construct a multi dimensional array by enclosing the indexes in [] in the name attribute:
    HTML Code:
    <input type="text" value="0" size="3" maxlength="4" name="thetext[dim1][dim2]" />
    Also, notice how the all attibutes are in lower case and enclosed in quotes. You should always do this.

    To access it in PHP:
    PHP Code:
    echo($_POST['thetext']['dim1']['dim2']); 
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Mar 2005
    Posts
    103

    Re: GET to Array

    thanks! that makes things a lot easier!

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