IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

PHP & Base de données Discussion :

moteur recherche et pagination


Sujet :

PHP & Base de données

  1. #1
    Candidat au Club
    Homme Profil pro
    Webmaster
    Inscrit en
    Octobre 2018
    Messages
    12
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Corrèze (Limousin)

    Informations professionnelles :
    Activité : Webmaster

    Informations forums :
    Inscription : Octobre 2018
    Messages : 12
    Points : 4
    Points
    4
    Par défaut moteur recherche et pagination
    Bonjour,

    J'ai essayé de construire ce moteur de recherche avec des switch, ça fonctionnait bien avant que je mette le système de pagination. J'ai du faire un smilblick parce que je n'ai plus les résultats qui s'affichent et je n'ai plus rien dans ma requête : Search :
    Code sql : Sélectionner tout - Visualiser dans une fenêtre à part
    SELECT * FROM produits WHERE MATCH(Nom2) AGAINST('%%') ORDER BY MATCH(Nom2) AGAINST('%%') DESC LIMIT 0, 10

    Il ne trouve plus rien dans la variable $search.
    Notice: Undefined index: search in C:\wamp\www\

    Est-ce que vous voyez quelque chose qui pourrait expliquer que ça ne fonctionne plus ?
    merci parce que je tourne dans tous les sens et je ne trouve pas

    Code php : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
     
    <?php 
    include 'connect.inc.php';
     
    // Numero de page (1 par défaut)
    if( isset($_GET['page']) && is_numeric($_GET['page']) )
        $page = $_GET['page'];
    else
        $page = 1;
     
    // Nombre d'info par page
    $pagination = 10;
    // Numéro du 1er enregistrement à lire
    $limit_start = ($page - 1) * $pagination;
     
     
     
     
    //RECHERCHE 
     
    //On récupère les données de recherche et les types de choix
    $recherche = (isset($_POST['recherche']) ? htmlspecialchars(stripslashes($_POST['search'])) : '');
     
    $normal = (isset($_POST['mode']) && $_POST['mode'] == 'normal') ? ' selected="selected"' : '' ;
    $boolean_and = (isset($_POST['mode']) && $_POST['mode'] == 'boolean_and') ? ' selected="selected"' : '' ;
    $boolean_or = (isset($_POST['mode']) && $_POST['mode'] == 'boolean_or') ? ' selected="selected"' : '' ;
     
    $type = (isset($_POST['type']) && $_POST['type'] == 'product_number1') ? ' selected="selected"' : '' ;
    $type = (isset($_POST['type']) && $_POST['type'] == 'product_name2') ? ' selected="selected"' : '' ;
    $type = (isset($_POST['type']) && $_POST['type'] == '_formula3') ? ' selected="selected"' : '' ;
    $type = (isset($_POST['type']) && $_POST['type'] == '_number4') ? ' selected="selected"' : '' ;
    $type = (isset($_POST['type']) && $_POST['type'] == '_number5') ? ' selected="selected"' : '' ;
     
    	if(isset($_POST['submit']))
    	{
    		$type = $_POST['type'];
    		$mode = $_POST['mode'];
    		$search = $_POST['search'];
    		//$limit='';
    	}
     
    	elseif(isset($_GET['type']) && isset($_GET['mode']) && isset($_GET['search']))
    	{
    		$type = $_GET['type'];
    		$mode = $_GET['mode'];
    		$search = urldecode($_GET['search']);
    	}
     
    	else
    	{
    		$search=null;
    		$type=null;
    		$mode=null;
    	}
     
     
    // RECHERCHE et requêtes
    $tableau_recherche = array($mode, $type);
    $search=mysql_real_escape_string($search);
     
    echo $search;
    switch ($tableau_recherche){
     
     
    //----------------------------------------- CODE_ARTICLE ----------------------------------------------------------------------
    //1_ recherche code_article mode normal et product_number1
    case array("normal", "product_number1"):
    ?>
     
    <h3>Recherche exacte dans product number :</h3>
     
    <?php
    $sql_val = " SELECT *
         		 FROM produits
         		 WHERE MATCH(code_article) AGAINST('%".$search."%')
         		 ORDER BY MATCH(code_article) AGAINST('%".$search."%') DESC LIMIT $limit_start, $pagination";
     
    echo $reqProducts;
    break;
     
     
    //1_ recherche code_article mode boolean and et product_number1
    case array("boolean_and", "product_number1"):
    ?>
     
    <h3>Mode boolean :</h3>
     
    <?php
    define("MOT_COURT", 1);
     
    $words = explode(" ", $search);
    $search_params = array();
    foreach ($words as $word) 
    {
        if (strlen($word) > MOT_COURT) 
    	{  
            // pour chaque mot, on construit la chaine de recherche
            $search_params[] = " code_article LIKE '%".mysql_real_escape_string($word)."%' ";
        }
    }
    $andor = "and"; // ou "or" selon un test, une préférence....
     
    $sql_val = "select * from produits where " . implode(" $andor ", $search_params);
     
    ?>
     
    Search :
    <strong>
    <?php echo $search; ?>
    </strong>
     
    <?php
    echo $sql_val;
    break;
     
    //1_ recherche code_article mode boolean or et product_number1
    case array("boolean_or", "product_number1"):
    ?>
     
    <h3>Mode boolean :</h3>
     
    <?php
    // Extraction des mots clefs
    $mots = explode(" ", $search );
    if( count( $mots ) > 0 ) {
       $sql_val = "SELECT * FROM produits WHERE ";
       for( $i = 0; $i < count( $mots ); $i++ ) {
    	  $sql_val .= "code_article LIKE '". $mots[$i] ."%'";
          if( $i < count( $mots ) - 1 )
             $sql_val .= " OR ";
       }
       $sql_val .= " ORDER BY id DESC LIMIT $limit_start, $pagination";
    } else {
       // Aucune donnée
    }
    ?>
     
    Search :
    <strong>
    <?php echo $mots; ?>
    </strong>
     
    <?php
    echo $sql_val;
    break;
     
     
    // --------------------------------------- Nom2 ----------------------------------------------------------------------
    //2_ recherche Nom2 normal et product name
    case array("normal", "product_name2"):
    ?>
     
    <h3>Mode normal et search product name :</h3>
     
    <?php
    $sql_val = " SELECT *
         		 FROM produits
         		 WHERE MATCH(Nom2) AGAINST('%".$search."%')
         		 ORDER BY MATCH(Nom2) AGAINST('%".$search."%') DESC LIMIT $limit_start, $pagination";		 
    ?>
     
    Search :
    <strong>
    <?php echo $search; ?>
    </strong>
     
    <?php
    echo $sql_val;
    break;
     
    //2_ recherche booleen_and et product name
    case array("boolean_and", "product_name2"):
    ?>
     
    Boolean_and mode and search product name:
     
    <?php
    $mots = explode("_", $search );
    if( count( $mots ) > 0 ) {
       $sql_val = "SELECT * FROM produits WHERE ";
       for( $i = 0; $i < count( $mots ); $i++ ) {
    	  $sql_val .= "Nom2 LIKE '". $mots[$i] ."%'";
          if( $i < count( $mots ) - 1 )
             $sql_val .= " and ";
       }
       $sql_val .= " ORDER BY id DESC LIMIT $limit_start, $pagination";
    } else {
       // Aucune donnée
    }
    ?>
     
    Search :
    <strong>
    <?php echo $search; ?>
    </strong>
     
    <?php
    break;
     
     
     
    //2_ recherche booleen or et product name
    case array("boolean_or", "product_name2"):
    ?>
     
    <h3>Boolean_or mode and search product name:</h3>
     
    <?php
       // fractionne la recherche en mots $motrecherche(1) $motrecherche(2) ...
       $motrecherche=explode(" ",$recherche);
       $WHERE = "WHERE";
       $count = 0;
       reset ($motrecherche);
       while(list($key, $data) = each($motrecherche))
       {
    		$count = $count + 1;
    		if ($count == 1)   $WHERE .= "     Nom2 LIKE '%" . $data . "%' "; 
    		else               $WHERE .= "  OR Nom2 LIKE '%" . $data . "%' "; 
       }
     
    $sql_val = "SELECT * FROM produits $WHERE DESC LIMIT $limit_start, $pagination";
     
    echo $sql_val;
    break;
     
    //3_ RECHERCHE normale formule moléculaire [[[[[[[[[[[[[[[[[[[[[
    case array("normal", "_formula3"):
    ?>
     
    <h3>Mode normal et recherche  formula :</h3>
     
    <?php
    $sql_val = "SELECT * from produits WHERE formule_mol LIKE ('%".$recherche."%') DESC LIMIT $limit_start, $pagination"; 
     
    echo $sql_val;
    break;
     
     
    //3_ recherche booleen_and et formule moléculaire  formule_mol
    case array("boolean_and", "_formula3"):
    ?>
     
    Boolean_and mode and  formula:
     
    <?php
    $mots = explode("_", $recherche );
    if( count( $mots ) > 0 ) {
       $sql_val = "SELECT * FROM produits WHERE ";
       for( $i = 0; $i < count( $mots ); $i++ ) {
    	  $sql_val .= "formule_mol LIKE '". $mots[$i] ."%'";
          if( $i < count( $mots ) - 1 )
             $sql_val .= " and ";
       }
       $sql_val .= " ORDER BY id DESC LIMIT $limit_start, $pagination";
    } else {
       // Aucune donnée
    }
    ?>
     
    recherche :
    <strong>
    <?php echo $recherche; ?>
    </strong>
     
    <?php
    echo $sql_val;
    break;
     
    //3_ recherche booleen_or et formule moléculaire
    case array("boolean_or", "_formula3"):
    ?>
     
    <h3>Boolean_or mode and recherche product name:</h3>
     
    <?php
       // fractionne la recherche en mots $motrecherche(1) $motrecherche(2) ...
       $motrecherche=explode(" ",$recherche);
       $WHERE = "WHERE";
       $count = 0;
       reset ($motrecherche);
       while(list($key, $data) = each($motrecherche))
       {
    		$count = $count + 1;
    		if ($count == 1)   $WHERE .= "     formule_mol LIKE '%" . $data . "%' "; 
    		else               $WHERE .= "  OR formule_mol LIKE '%" . $data . "%' "; 
       }
     
    $sql_val = "SELECT * FROM produits $WHERE DESC LIMIT $limit_start, $pagination";
     
    echo $sql_val;
    break;
     
     
    //4_ RECHERCHE normale CA
    case array("normal", "cas_number4"):
    ?>
     
    <h3>>Mode normal et recherche ca :</h3>
     
    <?php
    $sql_val = "SELECT * from produits WHERE cas LIKE ('%".$recherche."%') DESC LIMIT $limit_start, $pagination"; 
     
    echo $sql_val;
    break;
     
     
    //4_ recherche booleen_and et cas
    case array("boolean_or", "cas_number4"):
    ?>
     
    Boolean_or mode and recherche cas :
     
    <?php
    $mots = explode("_", $recherche );
    if( count( $mots ) > 0 ) {
       $sql_val = "SELECT * FROM produits WHERE ";
       for( $i = 0; $i < count( $mots ); $i++ ) {
    	  $sql_val .= "cas LIKE '". $mots[$i] ."%'";
          if( $i < count( $mots ) - 1 )
             $sql_val .= " and ";
       }
       $sql_val .= " ORDER BY id DESC LIMIT $limit_start, $pagination";
    } else {
       // Aucune donnée
    }
    ?> 
     
    recherche :
    <strong>
    <?php echo $recherche; ?>
    </strong>
     
    <?php
    echo $sql_val;
    break;
     
     
    //4_ recherche booleen or et cas
    case array("boolean_or", "cas_number4"):
    ?>
     
    <h3>Boolean_or mode and recherche product name:</h3>
     
    <?php
       // fractionne la recherche en mots $motrecherche(1) $motrecherche(2) ...
       $motrecherche=explode(" ",$recherche);
       $WHERE = "WHERE";
       $count = 0;
       reset ($motrecherche);
       while(list($key, $data) = each($motrecherche))
       {
    		$count = $count + 1;
    		if ($count == 1)   $WHERE .= "     cas LIKE '%" . $data . "%' "; 
    		else               $WHERE .= "  OR cas LIKE '%" . $data . "%' "; 
       }
     
    $sql_val = "SELECT * FROM produits $WHERE DESC LIMIT $limit_start, $pagination";
     
    echo $sql_val;
    break;
     
    //5_ RECHERCHE normale  number
    case array("normal", "_number5"):
     
    ?>
     
    <h3>Mode normal et recherche  number :</h3>
     
    <?php
    //fulltext sur ref_fr
    $sql_val = " SELECT *
         		 FROM produits
         		 WHERE MATCH(ref_fr) AGAINST('%".$recherche."%')
         		 ORDER BY MATCH(ref_fr) AGAINST('%".$recherche."%') DESC LIMIT $limit_start, $pagination";
     
    echo $sql_val;
    break;
     
    //5_ recherche booleen_and et ref_fr 
    case array("boolean_and", "_number5"):
    ?>
     
    Boolean_or mode and recherche cas :
     
    <?php
    $mots = explode("_", $recherche );
    if( count( $mots ) > 0 ) {
       $sql_val = "SELECT * FROM produits WHERE ";
       for( $i = 0; $i < count( $mots ); $i++ ) {
    	  $sql_val .= "ref_fr LIKE '". $mots[$i] ."%'";
          if( $i < count( $mots ) - 1 )
             $sql_val .= " and ";
       }
       $sql_val .= " ORDER BY id DESC LIMIT $limit_start, $pagination";
    } else {
       // Aucune donnée
    }
    ?>
     
    recherche :
    <strong>
    <?php echo $recherche; ?>
    </strong>
     
    <?php
    echo $sql_val;
    break;
     
    //5_ recherche booleen or et ref_fr
    case array("boolean_or", "_number5"):
    ?>
     
    <h3>Boolean_or mode and recherche product name:</h3>
     
    <?php
       // fractionne la recherche en mots $motrecherche(1) $motrecherche(2) ...
       $motrecherche=explode(" ",$recherche);
       $WHERE = "WHERE";
       $count = 0;
       reset ($motrecherche);
       while(list($key, $data) = each($motrecherche))
       {
    		$count = $count + 1;
    		if ($count == 1)   $WHERE .= "     ref_fr LIKE '%" . $data . "%' "; 
    		else               $WHERE .= "  OR ref_fr LIKE '%" . $data . "%' "; 
       }
     
    $sql_val = "SELECT * FROM produits $WHERE DESC LIMIT $limit_start, $pagination";
     
    echo $sql_val;
    break;
    }
     
     
    				// ------------------------- RESULTAT RECHERCHE-----------------------------				
    					$resultat = mysql_query($sql_val);
     
    				?>  
     
     
    <form method="post" action="<?php $_SERVER['PHP_SELF'] ?>">				
     
    				  <table width="90%" border="0">
    					<tr>
    					  <td width="20%" height="43">
    					  <input type="radio" name="type" id="product_number1"  value="product_number1"<?php if($type=='product_number1'){echo 'checked="checked"';} ?> checked="checked" /> Product number</td>
    					  <td width="19%">
    					  <input type="radio" name="type" id="product_name2"  value="product_name2"<?php if($type=='product_name2'){echo 'checked="checked"';} ?> /> Product name</td>
    					  <td width="20%">
    					  <input type="radio" name="type" id="_formula3"  value="_formula3"<?php if($type=='_formula3'){echo 'checked="checked"';} ?> />  formula</td>
    					  <td width="20%">
    					  <input type="radio"name="type" id="_number4"  value="_number4"<?php if($type=='_number4'){echo 'checked="checked"';} ?>  />  number</td>
    					  <td width="21%">
    					  <input type="radio" name="type" id="_number5"  value="_number5"<?php if($type=='_number5'){echo 'checked="checked"';} ?> />  number</td>
    					 </tr>
     
    					<tr>
    					  <td colspan="3">
    					  <table width="100%" border="0">
    						<tr>
    						  <td colspan="2">recherche for: 
    							<input type="text" size="40" name="recherche" class="inputrecherche" value="<?php echo $recherche; ?>" style="margin-top: 0px;width:350px" onKeyUp="javascript:couleur(this);"/>
    						  </td>
    						</tr>
    						<tr>
    						  <td width="28%">&nbsp;</td>
    						  <td width="72%">&nbsp;</td>
    						</tr>
    					  </table>
    					  </td>
    					  <td colspan="2">
    					  Mode:
    						  <select name="mode" type="text" value="" >
    						  <option value="normal"<?php echo $normal; ?>/>  Normal </option>
    						  <option value="boolean_and"<?php echo $boolean_and; ?>/> Boolean and </option>
    						  <option value="boolean_or"<?php echo $boolean_or; ?>/>Boolean or</option>
    						  </select>
    						<input type="submit" name="submit" value="GO" />	  
    				  	</td>
    					</tr>
    					</table>			
     
    <?php
     
    				// Traitement et affichage des données
    				while ($rangm = mysql_fetch_assoc($resultat)) {
     
     
     
    					echo "<h1>{$rangm['code_article']}</h1>";
    					echo $rangm['designation'];
    					echo "<hr/>";
     
    }
     
     
     
    	// Nb d'enregistrement total
    	$nb_total = mysql_query('SELECT COUNT(*) AS nb_total FROM produits');
    	$nb_total = mysql_fetch_array($nb_total);
    	$nb_total = $nb_total['nb_total'];
     
    	// Pagination
    	$nb_pages = ceil($nb_total / $pagination);
     
    	echo '<p>[ Page :';
    	// Boucle sur les pages
    	for ($i = 1 ; $i <= $nb_pages ; $i++) {
    		if ($i == $page )
    			echo " $i";
    		else
    			echo " <a href=\"?page_recherche=$i\">$i</a> ";
    	}
    	echo ' ]</p>';	
     
     
    ?>

  2. #2
    Membre émérite
    Avatar de badaze
    Homme Profil pro
    Chef de projets info
    Inscrit en
    Septembre 2002
    Messages
    1 412
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ain (Rhône Alpes)

    Informations professionnelles :
    Activité : Chef de projets info
    Secteur : Transports

    Informations forums :
    Inscription : Septembre 2002
    Messages : 1 412
    Points : 2 522
    Points
    2 522
    Par défaut
    Il faut que tu mettes le mode, le type de recherche et la recherche dans l'url. ATTENTION ce seront des paramètres $_GET.

    Code php : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    echo " <a href=\"?page_recherche=$i\">$i</a> ";
    Cela ne sert à rien d'optimiser quelque chose qui ne fonctionne pas.

    Mon site : www.emmella.fr

    Je recherche le manuel de l'Olivetti Logos 80B.

  3. #3
    Expert éminent Avatar de CosmoKnacki
    Homme Profil pro
    Justicier interdimensionnel
    Inscrit en
    Mars 2009
    Messages
    2 848
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Charente Maritime (Poitou Charente)

    Informations professionnelles :
    Activité : Justicier interdimensionnel

    Informations forums :
    Inscription : Mars 2009
    Messages : 2 848
    Points : 6 535
    Points
    6 535
    Par défaut
    Ligne 22:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    $recherche = (isset($_POST['recherche']) ? htmlspecialchars(stripslashes($_POST['search'])) : '');
    $_POST['recherche'] ou $_POST['search']?

    Il y a beaucoup à dire sur ton code, mais la première urgence est de ne plus utiliser l'extension mysql (obsolète depuis PHP 5.5, retirée depuis PHP 7.0). Donc "out" toutes les fonctions qui commence par mysql_ et utilise PDO à la place (il y a des tutoriels disponibles sur le site.).
    Brachygobius xanthozonus
    Ctenobrycon Gymnocorymbus

  4. #4
    Candidat au Club
    Homme Profil pro
    Webmaster
    Inscrit en
    Octobre 2018
    Messages
    12
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Corrèze (Limousin)

    Informations professionnelles :
    Activité : Webmaster

    Informations forums :
    Inscription : Octobre 2018
    Messages : 12
    Points : 4
    Points
    4
    Par défaut
    Merci pour les réponses, je veux bien que tu critiques mon code CosmoKnacki si ça peut me permettre de l'améliorer.

    J'ai rajouté les paramètres pour faire afficher le mode, le type de recherche et la recherche dans l'url mais je ne récupère toujours pas mes résultats, est-ce que j'ai oublié quelque chose ?

    Code php : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    echo " <a href=\"?page_recherche=$i&search=$search&type=$type&mode=$mode\">$i</a> ";

    Pour mysql, je vais le changer mais j'amerai améliorer le fonctionnement dans un premier temps, ça reste en local pour l'instant. Et c'est , recherche c'est une erreur.

    Merci de me consacrer du temps

  5. #5
    Membre émérite
    Avatar de badaze
    Homme Profil pro
    Chef de projets info
    Inscrit en
    Septembre 2002
    Messages
    1 412
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ain (Rhône Alpes)

    Informations professionnelles :
    Activité : Chef de projets info
    Secteur : Transports

    Informations forums :
    Inscription : Septembre 2002
    Messages : 1 412
    Points : 2 522
    Points
    2 522
    Par défaut
    Est-ce que les nouveaux paramètres sont valorisés ? Faire un echo de ces données.

    Dans ton premier message tu as

    Code php : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    echo " <a href=\"?page_recherche=$i\">$i</a> ";

    et maintenant tu mets
    Code php : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    echo " <a href=\"?rapid_search2=$i&search=$search&type=$type&mode=$mode\">$i</a> "

    Est-ce que tu as modifié le reste du script car déjà dans le script initial tu envoies "page_recherche" alors que tu as un $_GET['page'] ?
    Cela ne sert à rien d'optimiser quelque chose qui ne fonctionne pas.

    Mon site : www.emmella.fr

    Je recherche le manuel de l'Olivetti Logos 80B.

  6. #6
    Candidat au Club
    Homme Profil pro
    Webmaster
    Inscrit en
    Octobre 2018
    Messages
    12
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Corrèze (Limousin)

    Informations professionnelles :
    Activité : Webmaster

    Informations forums :
    Inscription : Octobre 2018
    Messages : 12
    Points : 4
    Points
    4
    Par défaut
    Non c'est bien page_recherche par contre je continue de travailler sur mon code d'origine, c'est pour ça que le nom des variables a été changé mais le fonctionnement reste le même.
    Mes paramètres mode, recherche et type sont valorisés, je les teste au début. Quand je teste avec un requête toute simple sans mes switch, il trouve bien mes réponses et la pagination fonctionne, quand je teste avec mes switchs, j'ai la pagination qui me sort tous les résultats de la table mais je n'ai pas de résultats qui s'affichent. Ma requête s'affiche bien par contre, il trouve bien le mot cherché dans $search.
    Merci

  7. #7
    Membre émérite
    Avatar de badaze
    Homme Profil pro
    Chef de projets info
    Inscrit en
    Septembre 2002
    Messages
    1 412
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ain (Rhône Alpes)

    Informations professionnelles :
    Activité : Chef de projets info
    Secteur : Transports

    Informations forums :
    Inscription : Septembre 2002
    Messages : 1 412
    Points : 2 522
    Points
    2 522
    Par défaut
    Pendant qu'on y est. Il faut contrôler qu'au final $page est toujours > 0 car rien n'empêche de passer 'page' à 0.

    Code php : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
     
    // Numero de page (1 par défaut)
    if( isset($_GET['page']) && is_numeric($_GET['page']) )
        $page = $_GET['page'];
    else
        $page = 1;
    if ($page <=0)
    {
       $page = 1;
    }

    Code php : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
     
    // Numero de page (1 par défaut)
    $page = 0;
    if( isset($_GET['page']) && is_numeric($_GET['page']) )
    {
       $page = $_GET['page'];
    }
    if ($page <=0)
     {
       $page = 1;
     }
    Cela ne sert à rien d'optimiser quelque chose qui ne fonctionne pas.

    Mon site : www.emmella.fr

    Je recherche le manuel de l'Olivetti Logos 80B.

  8. #8
    Expert éminent Avatar de CosmoKnacki
    Homme Profil pro
    Justicier interdimensionnel
    Inscrit en
    Mars 2009
    Messages
    2 848
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Charente Maritime (Poitou Charente)

    Informations professionnelles :
    Activité : Justicier interdimensionnel

    Informations forums :
    Inscription : Mars 2009
    Messages : 2 848
    Points : 6 535
    Points
    6 535
    Par défaut
    Tu peux aussi utiliser les filtres de validations pour contrôler les paramètres transmis en GET et POST:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    $page = isset($_GET['page'])
        ? filter_var($_GET['page'], FILTER_VALIDATE_INT, ['options' => ['default' => 1, 'min_range' => 1]])
        : 1;
    Brachygobius xanthozonus
    Ctenobrycon Gymnocorymbus

  9. #9
    Candidat au Club
    Homme Profil pro
    Webmaster
    Inscrit en
    Octobre 2018
    Messages
    12
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Corrèze (Limousin)

    Informations professionnelles :
    Activité : Webmaster

    Informations forums :
    Inscription : Octobre 2018
    Messages : 12
    Points : 4
    Points
    4
    Par défaut
    Merci pour ces infos, ça m'aide à améliorer mon code

    J'ai résussi à afficher mes résultats en rajoutant ceci :
    Code php : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    $resultat = mysql_query($sql_val or die('Erreur SQL !<br />'.$sql_val.'<br />'.mysql_error());

    J'ai une ressource id #8 qui s'affiche dans ma requête :
    Code php : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    Recherche : mot SELECT * FROM produits WHERE MATCH(Nom2) AGAINST('%mot%') ORDER BY MATCH(Nom2) AGAINST('%mot%') DESC LIMIT 0, 10 Resource id #8

    Merci

  10. #10
    Modératrice
    Avatar de Celira
    Femme Profil pro
    Développeuse PHP/Java
    Inscrit en
    Avril 2007
    Messages
    8 633
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 39
    Localisation : France

    Informations professionnelles :
    Activité : Développeuse PHP/Java
    Secteur : Industrie

    Informations forums :
    Inscription : Avril 2007
    Messages : 8 633
    Points : 16 372
    Points
    16 372
    Par défaut
    Il faut parcourir les résultats de ta requête en utilisant une boucle (si tu attends plusieurs lignes) et une fonction de récupération de données comme mysql_​fetch_​assoc.

    Mais il faut surtout abandonner les fonctions mysql_xxxx au profit de PDO, étant donné que l'API Mysql n'existe plus en PHP7.
    A lire : PDO une soupe et au lit !
    Modératrice PHP
    Aucun navigateur ne propose d'extension boule-de-cristal : postez votre code et vos messages d'erreurs. (Rappel : "ça ne marche pas" n'est pas un message d'erreur)
    Cherchez un peu avant poser votre question : Cours et Tutoriels PHP - FAQ PHP - PDO une soupe et au lit !.

    Affichez votre code en couleurs : [CODE=php][/CODE] (bouton # de l'éditeur) et [C=php][/C]

Discussions similaires

  1. [MySQL] moteur recherche multi pagination suivant recherche
    Par speedylol dans le forum PHP & Base de données
    Réponses: 51
    Dernier message: 13/01/2017, 11h51
  2. Moteur de recherche et pagination
    Par spiralfriz dans le forum Symfony
    Réponses: 0
    Dernier message: 18/11/2016, 03h14
  3. [MySQL] resultat d'un moteur de recherche et pagination
    Par mustapha_aim dans le forum PHP & Base de données
    Réponses: 2
    Dernier message: 15/07/2010, 17h05
  4. [Zend_Lucene] Moteur de recherche et pagination
    Par Merfolk dans le forum Autres composants
    Réponses: 4
    Dernier message: 23/09/2009, 15h18
  5. Moteur recherche Blork Engine
    Par flopad dans le forum EDI, CMS, Outils, Scripts et API
    Réponses: 1
    Dernier message: 24/10/2005, 12h38

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo