How can I make this array with data from a database?
如何使用数据库中的数据创建此数组?
$array=array("a"=>"Apple","b"=>"Ball","c"=>"Cat");
I have a database table with column letter
and value
.
我有一个包含列字母和值的数据库表。
letter | value
|
a | Apple
b | Ball
c | Cat
I want "a"=>"Apple","b"=>"Ball","c"=>"Cat"
to be values from the database, using for loop, how is that possible?
我希望“a”=>“Apple”,“b”=>“Ball”,“c”=>“Cat”成为数据库中的值,使用for循环,这怎么可能?
Many thanks for any help!
非常感谢您的帮助!
1 个解决方案
#1
10
assuming you can do the connection and select
假设您可以进行连接并选择
$array=array();
while ($row = mysql_fetch_assoc($result)) {
$array[$row['letter']]=$row['value'];
}
print_r($array);
#1
10
assuming you can do the connection and select
假设您可以进行连接并选择
$array=array();
while ($row = mysql_fetch_assoc($result)) {
$array[$row['letter']]=$row['value'];
}
print_r($array);