SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: Inserting arrays to a table

Hybrid View

  1. #1
    SitePoint Zealot
    Join Date
    Mar 2001
    Posts
    143
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Inserting arrays to a table

    Say I have a table with 1 field "question".

    I have a form with two text boxes. The first question[0] and the second question[1]. How will I be able to insert each text box entry as a new row via the insert mysql statement?
    Bardius

  2. #2
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try this out.
    i use to using something like this in C. Should still apply. After you get the values into $insert_value1, 2, 3 etc... you can just insert each value into your database.
    PHP Code:
    for($i=0$i<2$i++)
        {
         
    $insert_value $i $question[$i];
         
    $insert_value $i $question[$i];
        } 
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*

  3. #3
    SitePoint Enthusiast kcabobert's Avatar
    Join Date
    Aug 2001
    Location
    Topeka, KS
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I would just do this for the sake of extra code else where (then if the # of Qs grows use the for statements to build the inserts the insert them)
    PHP Code:

    for($i=0$icount($question); $i++) // the count($question) should make it loop until all question[x]s that exist have been inserted.
        
    {
         
    $insert_value = @mysql_query("INSERT INTO $tblname (Qcol)VALUES ('$question[$i]')");
    // or remove the @ to see errors (seeing errors is nice for debugging)
        

    Thats my thoughts.
    Microsoft's Motto: Resistance is futile, you will be assimilated.

    My dog's name is Jade; she is a Miniature pinscher.
    Click here to see some of her pictures

  4. #4
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  5. #5
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    serialize() goes against the purpose of a relational database here. By storing each question as a new record in the database, you not only will have easier access to the questions, you will be following a more efficient method of storing the data.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

Bookmarks

Posting Permissions

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