Reputation: 1093
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))
Upvotes: 0
Views: 10272
Reputation: 9858
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.
Upvotes: 7