Inserting MySQL table outputs into multidimensional array?

hi i wana insert table with some row and 3 column into multi mentional row,
i used below code
` $sql=“select * from sobhane”;
$res=mysqli_query($conection,$sql);
$i=0;

foreach ($res as $key => $res) {
echo $key;
$arrayName = array($key =>array(‘soid’ => $res[‘soid’],‘soname’ => $res[‘soname’],‘soprice’ => $res[‘soprice’]) );

}
echo $arrayName[0][‘soprice’];`

but i get this error when i echo this array Notice: Undefined offset: 0 in C:\xamp\htdocs\reserve\user\getweek.php on line 23
line 23 is echo $arrayName[0][‘soprice’];

im trying but i dont know why my array dont recofnize indexes,

$arrayName=array();
foreach ($res as $key => $res) {
echo $key;
$arrayName = array($key =>array(‘0’ => $res[‘soid’],‘1’ => $res[‘soname’],‘2’ => $res[‘soprice’]) );

}

done :wink:

This is so much easier with PDO.

$stmt = $connection->prepare("select * from sobhane");
$stmt->execute();
$rows = $stmt->fetchAll();

and $rows IS your multi dimensional array.

1 Like

Is the data from the “sobhane” table going to be inserted into another table in the same database?

1 Like

If it was then PHP wouldn’t be needed at all it could all be done in the one SQL command

1 Like

no into multidimentional array, and its done with help of mr @felgall

thanks to you all

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