add to muti densional array from html form Help lpease

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
BrettCarr
Forum Newbie
Posts: 22
Joined: Fri Feb 12, 2010 6:45 pm

add to muti densional array from html form Help lpease

Post by BrettCarr »

ok I want to add records to a mulit densional array from a form.
On POST I have It calling My function getArrayData() from my class Batcharray and from what i can see in the souce code of the form It puts the first record in
Here is what i see

Code: Select all

batch_date, 01-Jan-1970 <br />batch_number, 0 <br />original_proof_num, 596 <br />batch_status, New <br />invoice_num_ccaus, 852 <br />carrier, Toll <br />num_of_boxes, 5252 <br />toll_consign_num, 752752752 <br />custId, 75275275 <br />venueId, 752727 <br />bpay, 7427427 <br />proof_tracking_comments, 72 <br />veunue_comments, 272727272 <br />batcharray => Array
<html>
<head>
    <title></title>
 
    <link rel="STYLESHEET" type="text/css" href="/css/calendar.css">
    <script language="JavaScript" src="/scripts/simplecalendar.js" type="text/javascript"></script>
 


so Its working?? but I cannot put a second record in no matter what ive tried here is the PHP class im trying to put together im new to php Please tell me hoe to put in a new record

Code: Select all

<?
class Batcharray extends Database 
{
    
    
    
    
    
    
    
    
    
    function getArrayData()
    {
        
                            $batch_date                 = $_POST['batch_date'];
                            $batch_number               = $_POST['batch_number'];
                            $original_proof_num         = $_POST['original_proof_num']; 
                            $batch_status               = $_POST['batch_status'];
                            $invoice_num_ccaus          = $_POST['invoice_num_ccaus'];
                            $carrier                    = $_POST['carrier'];
                            $num_of_boxes               = $_POST['num_of_boxes'];
                            $toll_consign_num           = $_POST['toll_consign_num'];
                            $custId                     = $_POST['custId'];
                            $venueId                    = $_POST['venueId'];
                            $bpay                       = $_POST['bpay'];
                            $proof_tracking_comments    = $_POST['proof_tracking_comments'];
                            $veunue_comments            = $_POST['veunue_comments'];
        
    
        $batchlist = array( "batcharray" =>  array( "batch_date"                =>  $batch_date,
                                                    "batch_number"              =>  $batch_number ,
                                                    "original_proof_num"        =>  $original_proof_num,    
                                                    "batch_status"              =>  $batch_status,
                                                    "invoice_num_ccaus"         =>  $invoice_num_ccaus,
                                                    "carrier"                   =>  $carrier,
                                                    "num_of_boxes"              =>  $num_of_boxes,
                                                    "toll_consign_num"          =>  $toll_consign_num ,
                                                    "custId"                    =>  $custId ,
                                                    "venueId"                   =>  $venueId,
                                                    "bpay"                      =>  $bpay,
                                                    "proof_tracking_comments"   =>  $proof_tracking_comments,
                                                    "veunue_comments"           =>  $veunue_comments,
                                         )
                                    );
                                    
                                    
                                    
        
                                         
                                         
                                
                    /*$batchlist = array_merge((array)$batchlist,(array) $batcharray1);
                    print_r( $batchlist );*/
            
                                                
                    foreach( $batchlist["batcharray"] as $key => $value)
                    {
                        echo "$key, $value <br />";
                    }
            reset($batchlist);
while (list($key, $val) = each($batchlist)) {
    echo "$key => $val\n";
}
                
    }
    
}
    
?>
User avatar
manohoo
Forum Contributor
Posts: 201
Joined: Wed Dec 23, 2009 12:28 pm

Re: add to muti densional array from html form Help lpease

Post by manohoo »

Brett,

In database terms $_POST contains only one record with 13 fields. You are properly storing those fields and the corresponding values in an associative array.

But... your code can only process one record at a time, so I suggest that you place that record data in a database, then repeat the process as needed.

By the way, here are a couple of tricks that you can use to shorten your getArrayData() function:

Code: Select all

function getArrayData()
{   
    foreach ($_POST as $key=>$value) {
        $$key = $value;
        $batchlist['batcharray'][$key] = $value;
    }
}
Post Reply