Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2004
    Posts
    494

    Unanswered: how to create a sub array

    I'm trying to figure out how to make an array within an array. A sub array.
    The first array has 54 fields (for a db table). Then 90 records. In other words I'm trying to loop the 54 fields 90 times. This was extracted by an html table using regexp. And the first array was 54X90 results.
    PHP Code:
    $record = array();
    $fields = array();
    $numrecords count($tdInnerHTML[1])/count($thInnerHTML[1]); //to find out the number of records
    echo $numrecords;
    for(
    $rec=0$rec<$numrecords$rec++){ //90 records
        
    $records[$rec] = array();
        if(
    $rec==0){
            for (
    $getTds 0$getTds count($thInnerHTML[1]); $getTds++){ //54 columns per record
                
    $record[] = $tdInnerHTML[1][$getTds];
            }
        }else{
            
    $column count($thInnerHTML[1])*($rec+1);
            
    $min = (count($thInnerHTML[1])*$rec);
            for (
    $getTds $min $getTds $column$getTds++){ //54 columns per record
                
    $record[] = $tdInnerHTML[1][$getTds];
            }    
        }
        
    $records[$rec][] = implode(", "$record);


  2. #2
    Join Date
    Nov 2008
    Posts
    117
    Hi, This is not exactly for what you asked but example of using multiple arrays
    Code:
    <?php
    $ar = array(
           array("10", 11, 100, 100, "a"),
           array(   1,  2, "2",   3,   1)
          );
    array_multisort($ar[0], SORT_ASC, SORT_STRING,
                    $ar[1], SORT_NUMERIC, SORT_DESC);
    var_dump($ar);
    ?>

  3. #3
    Join Date
    Jul 2004
    Posts
    494
    ok. I have the old db table in html format. I deleted the old db table though. I recreated with some new fields and gotten rid of one field which existed in the the old. I'm concerned over how to insert it in.

    PHP Code:
    $contents_of_page file_get_contents('saveddbtable/view_blinks1.php.htm');
    preg_match_all("#<th.*>(.+)</th#Ui"$contents_of_page$thInnerHTML);
    $contents_of_page file_get_contents('saveddbtable/view_blinks1.php.htm');


    $tdInnerHTML str_replace("></td>"">\"\"</td>"$contents_of_page);//to fill the blank tds otherwise it doesn't show

    preg_match_all("#<td.*>(.+)</td#Ui"$tdInnerHTML$tdInnerHTML);

    $ths=0;
    for(
    $tds=0$tds<count($tdInnerHTML[1]); $tds++){
        if(
    $ths<count($thInnerHTML[1])){
            
    $thInnerHTML[1][$ths] = array();
        }
        
        echo 
    $thInnerHTML[1][$ths]." = ".$tdInnerHTML[1][$tds]."<br />\n";
        
    $thInnerHTML[1][$ths][] = $tdInnerHTML[1][$tds];
        if(
    $ths==count($thInnerHTML[1])-1){
            
    $ths=0;
        }else{
            
    $ths++;
        }

    Is it possible (as I'm trying) to make a sub array by taking the array of fields from the <th> tags and store up the <td> arrays of data in each field?

Posting Permissions

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