How to get a temporary array (line) into a 2 dimensional array?

I stuck on that problem to long and don’t know anymore where to ask.

From a database I retrieve data

try {

$conec = new Connection();
$con = $conec->Open();
if ($con) {

$sql = "SELECT * FROM tss WHERE ....";
$re = $con->query($sql);
foreach ($con->query($sql) as $row) {
$lastT[$i]['t_ex'] = $Mar = $row['t_ex'];
$lastT[$i]['t_sy'] = $Co = $row['t_sy'];
$lastT[$i]['t_ba'] = $Mat = $row['t_ba'];
...
$i++;
}
} else {
echo $con;
}
} catch (PDOException $ex) {
echo $ex->getMessage();
}

After fetching the data, I do some calculations add them to a temporary array and list the data as a row:

for ($x = 0; $x < $Tsize; $x++) {
$temparray[0] = $lastT[$x]['Co'];
$temparray[1] = $lastT[$x]['LA'];
$temparray[2] = $lastT[$x]['HB'];
....
echo $x . " " . $temparray[0] . " " . $temparray[1] . " " . $temparray[2] . " " . $temparray[3] . " " . $temparray[4] . " " . $temparray[5] . " " . $temparray[6] . " " . $temparray[7] . " " . $temparray[8] . $line_break;
} // close for loop

Perfect listing, just as I want it. However, I need to sort the list by the 6th column ($temparray[5])
Easy, just put the data of that temparray into a 2 dimensional array with each row exactly and do a sort by that column.

I feel like an idiot, I cannot get the data into a 2 dimensional array. Whatever I tried ended up to put the last temparray into the matrix as ONLY entry.

Can you give me a hint?

$twodarray = array();
for ($x = 0; $x > $Tsize; $x++) {
  ...
  $twodarray[] = $temparray;
}

(Alternatively, do it back when you’re foreaching the result, and just $twodarray[] = $row;

$con->fetchAll()

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.