how to define multi-dimensional array

Based on the Run Button in a Grid Application (Processing Records) tutorial, it define the global variable [total_chked] as a single dimension array at the event oninit -> [total_chked] = array();

For each record selected under the Button -> onRecord, it assign the field “contactname” to the global variable total_chked

[total_chked][$arr]={ContactName};

How can we modify this single dimensional array to multi-dimensional array? My key to the record consist of 4 fields, and I want to capture this 4 fields per record into an array [total_chked] such that at the Button -> onRecord,

$arr=[i];
[total_chked][$arr][0]={Branch};
[total_chked][$arr][1]={MDate};
[total_chked][$arr][2]={Queue};
[total_chked][$arr][3]={seqno};
[i]++;

When I try to retrieve the data from global var [total_chked], I get error message “Cannot use string offset as an array”

$Branch=[total_chked][0][0];

I tried using your example :

$array1 = array(0,0,0);
$array2 = array(0,0,0);
[total_chked] = ($array1,$array2);

but I got the following error message -> Parse error: syntax error, unexpected ‘,’ in grid_application.class.php

Re: how to define multi-dimensional array

Since SC uses [] to define global vars, it gets confused when you are trying to work with arrays. They need find different delimiters.

You can try adding spaces in you array elements: [ 0 ] / [ $arr ] instead of [0]/[$arr] and see if this helps.

The other solution is to create your own arrays using $_SESSION.

Regards,
Scott.

Re: how to define multi-dimensional array

I defined my own array using $_SESSION, but the resultant page came out blank, not sure if the array is passing the correct values. How to debug from scriptcase?

Grid_application -> under the onScriptInit, I declared
$_SESSION[‘total_chked’]=array();

Button -> onRecord, I declared;
$arr=[i];
$key= array(‘Branch’=>’{BranchRef}’,‘MDate’=>’{MPSDate}’,‘Queue’=>’{QueueNo}’,‘NumLet’=>’{NumLetters}’);
$_SESSION[‘total_chked’][$arr]=$key;
[i]++;

Blank Application -> onExecute, I declared
$tot = count($_SESSION[‘total_chked’]);
$pdf = new FPDF(‘P’,‘mm’,‘A4’);
for ($x=0;$x<$tot;$x++){
$Brn = $_SESSION[‘total_chked’][$x][‘Branch’];
$MPDate = $_SESSION[‘total_chked’][$x][‘MPSDate’];
$Que = $_SESSION[‘total_chked’][$x][‘Queue’];
$NLet = $_SESSION[‘total_chked’][$x][‘NumLet’];

sc_lookup(rs, $check_sql);

$pdf->Addpage();
$pdf->SetFont(‘Arial’,’ ',12);

};

Re: how to define multi-dimensional array

I have managed to solve the problem with the resultant was Blank as I have forgotten to add the following statement at the end:

$pdf->Output($reportname, “I”);

But the transfer of data via the $_SESSION is still not working, I did an echo on the variables and the following values was shown.

$Brn = $this->branchref
$MPDate = $this->branchref
$Que = $this->queueno
$NLet = $this->numletters

The correct parameter should show :

$Brn = ‘PRW’
$MPDate = ‘2008-10-17’
$Que = ‘10’
$NLet = 1

Appreciate if you could show me where my mistake at.

Thanks

Re: how to define multi-dimensional array

I have solved the problem which is due to the wrong declaration of a 2-dimensional array:

  1. Remove this declaration at Grid_application -> under the onScriptInit
    $_SESSION[‘total_chked’]=array();

  2. Replace the single quote with double quote in the array(“name”=>“value”) at Button -> onRecord,


$arr=[i];
$key= array("Branch"=>"{BranchRef}" , "MDate"=>"{MPSDate}" , "Queue"=>"{QueueNo}" ,"NumLet"=>"{NumLetters}");
$_SESSION['total_chked'][$arr] = $key;
[i]++;