Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jan 2007
    Posts
    64
    Thanks
    0
    Thanked 1 Time in 1 Post

    Angry Complex Loop / Insert MySQL

    This is sort of long and it has to do with putting irregular sized Matrix data into mySQL. I have been struggling with it for a long time.. I am desperate.

    Here's what the table looks like.
    It represents a matrix of values.

    tbl_matrix
    - UID <! Unique ID
    - Sheet_ID <! Sheet the data belongs to
    - XIndex <! self explanitory
    - YIndex <! self explanitory
    - CellValue <! the value that will be in the input shown later

    One sheet may have 3 rows of data and 4 columns

    And another sheet may have 5 rows of data and 5 columns.

    There is a max of 11 columns and 6 rows.

    I wrote code to generate a sample form that goes like this...

    PHP Code:
        print "<table border=1>\n";
        for( 
    $y 0$y <= $num_rows;  $y++ ){
            print 
    "      <tr>\n";
            
            for( 
    $x $low_xVal $inc$x <= $high_xVal$x += $inc){
                
                if (
    $x == $low_xVal-$inc){ print "            <td>" $y "</td>\n";
                }else{
                    if (
    $y==0){ print "            <td>" $x "</td>\n";}else{ print "            <td><input name=\"matrix" $x $y "\" type=\"text\" size=\"4\" /></td>\n";}    
                }
            }
            print 
    "      </tr>\n";
        }
        print 
    "</table>\n\n\n\n"
    That will draw out the matrix in the size that you tell it to...

    What do I do when it comes time to insert those values into the table without doing it one by one.... Is there a way to loop and insert?

    I am so lost on this.
    Last edited by jayemvee; 01-29-2007 at 03:50 AM.
    No trees were harmed in the transmission of this message.
    However, a rather large number of electrons were temporarily
    inconvenienced.

  • #2
    New Coder
    Join Date
    Jan 2007
    Posts
    64
    Thanks
    0
    Thanked 1 Time in 1 Post
    I figured it out... And just in case anyone else, I just ran a loop through $_POST["matrix" . $y . $x]; and it works...
    No trees were harmed in the transmission of this message.
    However, a rather large number of electrons were temporarily
    inconvenienced.


  •  

    Posting Permissions

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