[eluser]souri84[/eluser]
hi everybody,
I have a new problem. To begin, here is my code :
controller : visualisation.php
Code:
<?php
class Visualisation extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->helper('form');
}
public function index()
{
//informations générales
$data['title'] = 'Base test';
$data['heading'] = 'Que recherchez vous ?';
if(isset($_POST))
{
$search = $this->input->post('search');
$this->load->model('sidebar');
$data['menu']= $this->sidebar->get_all_entries();
if($search=='')
{
$this->load->view('recherche',$data);
}
else
{
$this->load->model('recherche');
$data['countResultats'] = $this->recherche->count_entries($search);
$data['search']= $search;
$this->load->view('recherche',$data);
}
}
}
}
?>
Model : recherche.php
Code:
<?php
class Recherche extends CI_Model
{
function __construct()
{
parent::__construct();
}
public function count_entries($search)
{
//on compte les entrées trouvées par la requête
$query = $this->db->prepare('SELECT P.NM_ID, P.CH_DOSSIER, P.CH_RAISON_SOCIALE, P.CH_NOM, P.CH_PRENOM, CP.CH_ADR1, CP.CH_ADR2, CP.CH_ADR3, CP.CH_CP, CP.CH_VILLE, CP.CH_PAYS
FROM f_personnes P
INNER JOIN f_coordonnees_post CP
WHERE P.NM_ID = CP.NM_ID_PERSONNE
AND
(P.CH_NOM = ?
OR P.CH_DOSSIER = ?
OR P.CH_RAISON_SOCIALE = ?)');
$data = $query->execute(array($search, $search, $search));
$data = $query->rowCount();
$query->closeCursor();
return $data;
}
public function get_all_entries($search)
{
//on met toutes les données récupérées dans un array
$query = $this->db->prepare('SELECT P.NM_ID, P.CH_DOSSIER, P.CH_RAISON_SOCIALE, P.CH_NOM, P.CH_PRENOM, CP.CH_ADR1, CP.CH_ADR2, CP.CH_ADR3, CP.CH_CP, CP.CH_VILLE, CP.CH_PAYS
FROM f_personnes P
INNER JOIN f_coordonnees_post CP
WHERE P.NM_ID = CP.NM_ID_PERSONNE
AND
(P.CH_NOM = ?
OR P.CH_DOSSIER = ?
OR P.CH_RAISON_SOCIALE = ?)');
$data = $query->execute(array($search, $search, $search));
$data = $query->fetchAll();
$query->closeCursor();
return $data;
}
}
?>
View : recherche.php
Code:
<<!-- FORMULAIRE DE RECHERCHE -->
<?php
form_open('visualisation/index');
echo form_input('search', '');
echo form_submit('submit_button', 'Rechercher');
?>
<!-- ON AFFICHE LE NOMBRE DE RESULTATS -->
<h3><?php if(isset($countResultats)) echo $countResultats.' entrées dans la base de données.'; ?></h3>
<h3><?php if(isset($search)) echo '$search vaut :'.$search; ?></h3>
<!-- ON AFFICHE LES RESULTATS DE LA REQUETE -->
<?php
if(isset($resultatsRecherche))
{
$tableResult = '<table>';
$tableResult .='<thead>';
$tableResult .='<tr>';
$tableResult .='<th colspan=10><h3>Résultats de la recherche</h3></th>';
$tableResult .='</tr>';
$tableResult .='</thead>';
$tableResult .='<tbody>';
$tableResult .='<tr>';
$tableResult .='<th><h3>N° de dossier</h3></th>';
$tableResult .='<th><h3>Raison sociale</h3></th>';
$tableResult .='<th><h3>Nom</h3></th>';
$tableResult .='<th><h3>Prénom</h3></th>';
$tableResult .='<th><h3>Adresse 1</h3></th>';
$tableResult .='<th><h3>Adresse 2</h3></th>';
$tableResult .='<th><h3>Adresse 3</h3></th>';
$tableResult .='<th><h3>Code postal</h3></th>';
$tableResult .='<th><h3>Ville</h3></th>';
$tableResult .='<th><h3>Pays</h3></th>';
$tableResult .='</tr>';
foreach($resultatsRecherche as $row)
{
$tableResult .='<tr>';
$tableResult .='<th><a >'.$row[0].$row[1].'</th>';
$tableResult .='<th>'.$row[2].'</th>';
$tableResult .='<th>'.$row[3].'</th>';
$tableResult .='<th>'.$row[4].'</th>';
$tableResult .='<th>'.$row[5].'</th>';
$tableResult .='<th>'.$row[6].'</th>';
$tableResult .='<th>'.$row[7].'</th>';
$tableResult .='<th>'.$row[8].'</th>';
$tableResult .='<th>'.$row[9].'</th>';
$tableResult .='<th>'.$row[10].'</th>';
$tableResult .='</tr>';
}
$tableResult .='</tbody>';
$tableResult .='</table>';
echo $tableResult;
}
?>
my problem is : When I click on the submit button, it's always nothing whereas, when it's the first view of this page, it's ok... I hope you see what I mean...
Thanks for your answers
Thibaut