Put result from mysql_query in php array
Translations
Englishالعربية
български
català
中文
čeština
dansk
Nederlands
eesti
suomi
français
Deutsch
Ελληνικά
עברית
हिंदी
magyar
Bahasa Indonesia
italiano
日本語
한국어
latviešu
lietuvių
norsk
polski
Português
română
русский
slovenčina
slovenski
español
svenska
ไทย
Türkçe
українська
Tiếng Việt
I want to get some results from the MySQL database and put them in a array like this:
array("value2", "value2", "value3");
I have tried this:
$models = array();
$getmodels = mysql_query("select model from cars");
while($res = mysql_fetch_array($getmodels)) {
$models[$res['model']];
}
This does not work, when i check if the model is in array i get FALSE:
in_array($_REQUEST['model'], $models))
This question and answers originated from www.stackoverflow.com
Question by 2by (10/16/2011 3:48:27 PM)
Answer |
You were supposed to give each key a value, not turning the values into the keys Try this:
$models = array();
$getmodels = mysql_query("select model from cars");
while($res = mysql_fetch_assoc($getmodels)) {
$models[] = $res['model'];
}
This will create an array with numeric index. Each key will have the car's model as the value.
Answer by Kemal Fadillah
Find More Answers