If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > PHP > how to create a sub array

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-13-10, 23:06
gilgalbiblewhee gilgalbiblewhee is offline
Registered User
 
Join Date: Jul 2004
Posts: 494
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);

Reply With Quote
  #2 (permalink)  
Old 02-18-10, 03:28
bharanidharanit bharanidharanit is offline
Registered User
 
Join Date: Nov 2008
Posts: 115
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);
?>
Reply With Quote
  #3 (permalink)  
Old 02-20-10, 23:48
gilgalbiblewhee gilgalbiblewhee is offline
Registered User
 
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?
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On