Control result of database

This commit is contained in:
Michael RICOIS 2012-07-30 11:30:47 +00:00
parent e249753b24
commit fe37b17fac

View File

@ -92,11 +92,13 @@ class FieldsController extends Zend_Controller_Action
$sql->where("LOWER(NC) ".$where); $sql->where("LOWER(NC) ".$where);
} }
$result = $table->fetchAll($sql); $result = $table->fetchAll($sql);
foreach ($result as $item) { if (count($result)>0) {
$output[] = array( foreach ($result as $item) {
'label' => $item->NCCENR . ' (Région)', $output[] = array(
'value' => 'R'.$item->REGION 'label' => $item->NCCENR . ' (Région)',
); 'value' => 'R'.$item->REGION
);
}
} }
//Département //Département
@ -117,11 +119,13 @@ class FieldsController extends Zend_Controller_Action
$sql->where("LOWER(libdep) ".$where); $sql->where("LOWER(libdep) ".$where);
} }
$result = $table->fetchAll($sql); $result = $table->fetchAll($sql);
foreach ($result as $item) { if (count($result)>0) {
$output[] = array( foreach ($result as $item) {
'label' => $item->libdep . ' (Département)', $output[] = array(
'value' => 'D'.$item->numdep 'label' => $item->libdep . ' (Département)',
); 'value' => 'D'.$item->numdep
);
}
} }
//Ville //Ville
@ -142,24 +146,28 @@ class FieldsController extends Zend_Controller_Action
$sql->where("LOWER(Commune) ".$where); $sql->where("LOWER(Commune) ".$where);
} }
$result = $table->fetchAll($sql); $result = $table->fetchAll($sql);
foreach ($result as $item) { if (count($result)>0) {
$output[] = array( foreach ($result as $item) {
'label' => $item->Commune . ', '. $item->Codepos .' (Ville)', $output[] = array(
'value' => 'C'.$item->INSEE 'label' => $item->Commune . ', '. $item->Codepos .' (Ville)',
); 'value' => 'C'.$item->INSEE
);
}
} }
} elseif ( preg_match('/[0-9]{1,5}/', $q) ) { } elseif ( preg_match('/[0-9]{1,5}/', $q) ) {
//Code Postal //Code Postal
$table = new Application_Model_CodePostaux(); $table = new Application_Model_CodePostaux();
$sql = $table->select()->where('Codepos LIKE "'.$q.'%"'); $sql = $table->select()->where('Codepos LIKE "'.$q.'%"')->limit(1);
$result = $table->fetchAll($sql); $result = $table->fetchAll($sql);
foreach ($result as $item) { if (count($result)>0) {
$output[] = array( foreach ($result as $item) {
'label' => $item->Codepos . ' ( Code postal )', $output[] = array(
'value' => $item->Codepos 'label' => $item->Codepos . ' ( Code postal )',
); 'value' => $item->Codepos
);
}
} }
} }