obtenir l'array à partir de la base de données.
Salut
Voici le code original:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
<?php
$q = strtolower($_GET["q"]);
if (!$q) return;
$items = array(
"Great Bittern"=>"Botaurus stellaris",
"Little Grebe"=>"Tachybaptus ruficollis",
"Black-necked Grebe"=>"Podiceps nigricollis",
"Solitary Sandpiper"=>"Tringa solitaria",
"Heuglin's Gull"=>"Larus heuglini"
);
foreach ($items as $key=>$value) {
if (strpos(strtolower($key), $q) !== false) {
echo "$key|$value\n";
}
}
?> |
Je voudrais obtenir l'array à partir de la base de données j'ai fais comme ca mais elle ne marche pas:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
<?php
mysql_connect('localhost', 'root', '');
mysql_select_db('personne');
$q = strtolower($_GET["q"]);
if (!$q) return;
$sql = mysql_query("SELECT id, nom
FROM `personne`
");
$items = array($sql);
foreach ($items as $key=>$value) {
if (strpos(strtolower($key), $q) !== false) {
echo "$key|$value\n";
}
}
?>
Pouvez vous me dire comment corriger ce problème?
Merci d'avance |