TCPDF Report For Item Inventory (error)

I have created a TCPDF report step by step like following link:
http://www.scriptcase.net/knowledge/index.php?/Knowledgebase/Article/View/639/40/reportpdf-with-tcpdf-library
With compare of that I have 8 items.
The final pdf on PDF Report application is correct but in grid page when I select the records not process the pdf properly and not process new pdf and shows the first of process.
My codes are:
In the grid, the event OnScriptInit is following code:
[i] = 0;
[total_chked] = array();
[i1] = 0;
[total_chked1] = array();
[i2] = 0;
[total_chked2] = array();
[i3] = 0;
[total_chked3] = array();
[i4] = 0;
[total_chked4] = array();
[i5] = 0;
[total_chked5] = array();
[i6] = 0;
[total_chked6] = array();
[i7] = 0;
[total_chked7] = array();

In the event OnRecord of the run button I put the following code:
$arr=[i];
$arr1=[i1];
$arr2=[i2];
$arr3=[i3];
$arr4=[i4];
$arr5=[i5];
$arr6=[i6];
$arr7=[i7];
[total_chked][$arr] = {q.itemsid};
[total_chked1][$arr1] = {q.itemsDesp};
[total_chked2][$arr2] = {q.Specification};
[total_chked3][$arr3] = {q.tagno};
[total_chked4][$arr4] = {w.quantity};
[total_chked5][$arr5] = {r.staffname};
[total_chked6][$arr6] = {r.position};
[total_chked7][$arr7] = {r.unit};
[i]++;
[i1]++;
[i2]++;
[i3]++;
[i4]++;
[i5]++;
[i6]++;
[i7]++;
And in the OnFinish event, the code below:
$tot = count([total_chked]);
$tot1 = count([total_chked1]);
$tot2 = count([total_chked2]);
$tot3 = count([total_chked3]);
$tot4 = count([total_chked4]);
$tot5 = count([total_chked5]);
$tot6 = count([total_chked6]);
$tot7 = count([total_chked7]);

$itemsid = “”;
$itemsdesp = “”;
$specification = “”;
$tagno = “”;
$quantity = “”;
$staffname = “”;
$position = “”;
$unit = “”;

for($x=0;$x<$tot1;$x++){
$itemsid .= [total_chked][$x];
if($x == ($tot-1)){
$itemsid .= “.”;
} else {
$itemsid .= “,”;
}
}

for($x=0;$x<$tot1;$x++){
$itemsdesp .= [total_chked1][$x];
if($x == ($tot-1)){
$itemsdesp .= “.”;
} else {
$itemsdesp .= “,”;
}
}

for($x=0;$x<$tot1;$x++){
$specification .= [total_chked2][$x];
if($x == ($tot-1)){
$specification .= “.”;
} else {
$specification .= “,”;
}
}
for($x=0;$x<$tot1;$x++){
$tagno .= [total_chked3][$x];
if($x == ($tot-1)){
$tagno .= “.”;
} else {
$tagno .= “,”;
}
}
for($x=0;$x<$tot1;$x++){
$quantity .= [total_chked4][$x];
if($x == ($tot-1)){
$quantity .= “.”;
} else {
$quantity .= “,”;
}
}
for($x=0;$x<$tot1;$x++){
$staffname .= [total_chked5][$x];
if($x == ($tot-1)){
$staffname .= “.”;
} else {
$staffname .= “,”;
}
}
for($x=0;$x<$tot1;$x++){
$position .= [total_chked6][$x];
if($x == ($tot-1)){
$position .= “.”;
} else {
$position .= “,”;
}
}
for($x=0;$x<$tot1;$x++){
$unit .= [total_chked7][$x];
if($x == ($tot-1)){
$unit .= “.”;
} else {
$unit .= “,”;
}
}

[itemsid] = $itemsid;
[itemsdesp] = $itemsdesp;
[specification] = $specification;
[tagno] = $tagno;
[quantity] = $quantity;
[staffname] = $staffname;
[position] = $position;
[unit] = $unit;
sc_redir(pdfreport_items_1);

I don’t know where is the problem?