Create associative array from query

Posted under » PHP on 15 Feb 2022

Sometimes you need to create an associative array albeit a temporary one without having to connect to a database.

if ($result = $dbhandle -> query("SELECT * FROM question")) {

$kamchai = array();
while ($row = mysqli_fetch_assoc($result)) {
    $kamchai[$row['id']] = $row['mdq'];
    }
       $result -> free_result();
# now show the array
       foreach ($kamchai as $key => $value) {
       echo "<p>The $key is a $value.
"; } } $dbhandle -> close();

For creating Python array.

web security linux ubuntu python django git Raspberry apache mysql php drupal cake javascript css AWS data