Posted under » PHP » Python 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();
To show the array or list in python
kours = { 14 : 'PSY532', 13 : 'PRM317', 12 : 'ECE370', 11 : 'TSL507', 10 : 'ICT302' }
for key, value in kours.items():
print(f"{key}: {value}")
For creating Python list.