Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] form which operates once
#1

[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:
<&lt;!-- FORMULAIRE DE RECHERCHE --&gt;
            &lt;?php
            form_open('visualisation/index');
            echo form_input('search', '');
            echo form_submit('submit_button', 'Rechercher');
            
            ?&gt;
            
            &lt;!-- ON AFFICHE LE NOMBRE DE RESULTATS --&gt;
            <h3>&lt;?php if(isset($countResultats)) echo $countResultats.' entrées dans la base de données.'; ?&gt;</h3>
            <h3>&lt;?php if(isset($search)) echo '$search vaut :'.$search; ?&gt;</h3>
            
            &lt;!-- ON AFFICHE LES RESULTATS DE LA REQUETE --&gt;
            &lt;?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;
            }
            ?&gt;

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
#2

[eluser]souri84[/eluser]
SOLVED !

here is the malefic source code :

Code:
&lt;?php
            echo form_open('visualisation/index');
            echo form_input('search', '');
            echo form_submit('submit_button', 'Rechercher');
            echo form_close();
?&gt;




Theme © iAndrew 2016 - Forum software by © MyBB