Optimiser mes requetes

Répondre


Cette question est un moyen d’empêcher des soumissions automatisées de formulaires par des robots.
Smileys
:D :) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: =D> #-o =P~ :^o :non: :priere: 8-|
Voir plus de smileys
  Revue du sujet
 

  Étendre la vue Revue du sujet : Optimiser mes requetes

Re: Optimiser mes requetes

par yoann38 » 22 juil. 2016, 18:03

Bon,
Ce que j'ai fait c'est de créer une page test.html avec le code source généré par mon code PHP.
Et la déjà bonne nouvelle ça ne vient pas de mes images, ni de mon css et ni de mon js mais bien de mes requêtes je suppose car il ne me reste plus que ça.
Reste à savoir comment arrangé tout ca.
En testant la page sur l'outil de google je suis à 99/100 ( j'aurais bien aimé avoir des notes comme ça à l'école ) :p

Re: Optimiser mes requetes

par or 1 » 21 juil. 2016, 17:45

un bon outil, c'est d'executer toutes les requetes sql dans phpmyadmin et de cliquer sur "Expliquer SQL" pour voir si des index sont bien utilisés.

Re: Optimiser mes requetes

par yoann38 » 21 juil. 2016, 17:09

Alors je n'utilise aucun framework, c'est mieux au début pour apprendre.
J'ai donc tout en "pure code"

Alors je pense genre sélectionner l'essentiel au lieu d'utiliser * dans mes SELECT peut aider déjà.
Mais après ....
Mes image sont optimisé, js en fin de page ....

Le code pour les + motivé:
<?php  
 	 $path = NULL;
        if(empty($bdd)) {
            session_start();
            include("include/conndb.php");
             include("include/variables.php");
            $path = '../';
        }		

	
	if(!empty($_POST['ville'])) {
        header('Location: /sortie/region-'.$_REQUEST['region'].'/ville-de-'.simplification($_POST['ville']).'.html');
    }
	
	if(empty($_POST['ville'])) {
			if(empty($_POST['ville'])) $erreurs['ville'] = 'Renseigner une ville'; //vérification du pseudo
	}

	
	// Nombre d'annonce selon la région
	$count_annonce = "SELECT * FROM `loisirs`  JOIN `regions` ON `regions`.`region_id` = `loisirs`.`id_region` WHERE `loisirs`.`date_fin_sortie` > NOW() AND `loisirs`.`valide` = 1";
	$count_annonce .= !empty($_REQUEST['ville']) ? ' AND `loisirs`.`city` = "'.getRealValue($_REQUEST['ville']).'"' : NULL;
  	$count_annonce .= !empty($_REQUEST['region']) ? ' AND `regions`.`url` = "'.$_REQUEST['region'].'"' : NULL;
    $count_annonce .= !empty($_REQUEST['departement']) ? ' AND `loisirs`.`id_departements` = '.$_REQUEST['departement'] : NULL;
    $count_annonce .= !empty($_REQUEST['loisir']) ? ' AND `loisirs`.`id_type_loisirs` = "'.$_REQUEST['loisir'].'"' : NULL;
	$req = $bdd->query($count_annonce);
	$nb = $req->rowCount();
	$result = 'Actuellement près de '.$nb.' annonces';
	$result .=  !empty($region_id) && array_key_exists($region_id, $aRegion) ? ' en '.$aRegion[$region_id].'. ' : NULL;
	$result .= !empty($_REQUEST['departement']) ? ' en '.$depts[$_REQUEST['departement']] .'. ': NULL;
	$region_id = !empty($_REQUEST['region']) ? regionByUrl($_REQUEST['region']) : NULL;
	
	$meta_desc = !empty($_REQUEST['region']) && empty($_REQUEST['ville']) && empty($_REQUEST['loisir']) && empty($_REQUEST['departement']) ? ' Idée de sortie en '.$aRegion[$region_id].'. Votre weekend va être chargé! Concert, brocante, expostition ... Ca se passe en '.$aRegion[$region_id].'. Trouver la sortie de vos envies!' : NULL;	
	
	$meta_desc .= !empty($_REQUEST['region']) && !empty($_REQUEST['ville']) && empty($_REQUEST['loisir']) ? 'Vous êtes à la recherche d\'une idée de sortie en famille ou entre amis à '.ucfirst ($_REQUEST['ville']).' ! Aujourd\'hui ça va bouger à '.ucfirst(strtolower($_REQUEST['ville'])).'. Concert, exposition, vide-grenier, marché, visite ...' : NULL;	
	
	$meta_desc .= !empty($_REQUEST['loisir']) && !empty($_REQUEST['ville']) && !empty($_REQUEST['region']) ? 'Envie d\'une sortie '.strtolower($_REQUEST['loisir']).' à '.ucfirst ($_REQUEST['ville']).' ? Besoin de vous changez les idées ? Trouvez une idée de sortie à '.ucfirst ($_REQUEST['ville']).' n\'a jamais était aussi simple avec lasortie.fr' : NULL; // Choix du type d'évènement
	
	$meta_desc .= !empty($_REQUEST['loisir']) && empty($_REQUEST['ville']) && !empty($_REQUEST['region']) ? ucfirst(strtolower($_REQUEST['loisir'])).' en '.$aRegion[$region_id].'. Trouvez une sortie  '.strtolower($_REQUEST['loisir']).' n\'a jamais était aussi simple avec lasortie.fr' : NULL; // Choix du type d'évènement
	
	$meta_desc .= !empty($_REQUEST['loisir']) && !empty($_REQUEST['departement']) ? 'Retrouvez tous les sorties '.$_REQUEST['loisir'].' en '.$depts[$_REQUEST['departement']].' - '.$_REQUEST['departement'].'. Sortir en '.$depts[$_REQUEST['departement']].' n\'a jamais était aussi simple, trouver votre sortie facilement dès maintenant!' : NULL; // Choix du type d'évènement
	
	$meta_desc .= !empty($_REQUEST['ville']) && empty($_REQUEST['departement']) && empty($_REQUEST['loisir']) && empty($aRegion[$region_id]) ? 'Sorties  '.ucfirst ($_REQUEST['ville']).'. Changez vous les idées en trouvant une sortie à faire entre amis ou en famille sur lasortie.fr' : NULL; // Le département
	
	$meta_desc .= empty($_REQUEST['ville']) && !empty($_REQUEST['departement']) && !empty($_REQUEST['region']) ? 'Sortir en '.$depts[$_REQUEST['departement']].' ('.($_REQUEST['departement']).'). Des idées de sorties pour les grands et les petits. Vide-grenier, concert, exposition, marché, loto ...': NULL; // Le département
	
	if (empty($_REQUEST['region']) && empty($_REQUEST['loisir']) && empty($_REQUEST['departement']) && empty($_REQUEST['ville'])) {
		$titre =  'Idée de sortie: Ca va bouger ce week-end !';
	}else{
	$region_id = !empty($_REQUEST['region']) ? regionByUrl($_REQUEST['region']) : NULL;
	// Region
	$titre = !empty($_REQUEST['region']) && empty($_REQUEST['loisir']) && empty($_REQUEST['ville']) && empty($_REQUEST['departement']) ? " Sortir en ".$aRegion[$region_id].': Concert, visite, brocante, festival … ' : NULL;
	// Region et departement
	$titre .= !empty($_REQUEST['region']) && !empty($_REQUEST['departement']) && empty($_REQUEST['ville']) && empty($_REQUEST['loisir'])? 'Sortir en '.ucfirst ($depts[$_REQUEST['departement']]).' ('.($_REQUEST['departement']).') - lasortie.fr' : NULL; 
	// Region et loisirs
	$titre .= !empty($_REQUEST['region']) && empty($_REQUEST['departement']) && empty($_REQUEST['ville']) && !empty($_REQUEST['loisir'])? ucfirst(strtolower($_REQUEST['loisir'])).' en '  .$aRegion[$region_id].' - lasortie.fr' : NULL;
	// departement et loisirs
	$titre .= !empty($_REQUEST['region']) && !empty($_REQUEST['departement']) && empty($_REQUEST['ville']) && !empty($_REQUEST['loisir'])? 'Sortie '.strtolower($_REQUEST['loisir']).' en '  .$depts[$_REQUEST['departement']].' - lasortie.fr' : NULL; // Le département	
	// ville 
	$titre .= !empty($_REQUEST['region']) && empty($_REQUEST['departement']) && !empty($_REQUEST['ville']) && empty($_REQUEST['loisir'])? 'Sortie '.ucfirst(strtolower($_REQUEST['ville'])).' - concert, visite, brocante, festival … ' : NULL;
	// ville 
	$titre .= !empty($_REQUEST['region']) && empty($_REQUEST['departement']) && !empty($_REQUEST['ville']) && !empty($_REQUEST['loisir'])? 'Sortie '.$_REQUEST['loisir'].' à '.ucfirst(strtolower($_REQUEST['ville'])).' - lasortie.fr' : NULL; // Le département	
	}	
	?> 
<!DOCTYPE html>
<html lang="fr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php header( 'content-type: text/html; charset=utf-8' ); ?>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="robots" content="index,follow" /> 
<title><?php echo $titre ; ?></title>

<meta name="description" content="<?php echo $meta_desc ;?>" />
<?php $monUrl = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];?><link rel="canonical" href="<?php echo $monUrl ; ?>" />
<?php
$system_pagination = str_replace('.html' ,'',$monUrl);
if (empty($_GET['page'])) {
	echo '<link rel="next" href="'.$system_pagination.'-page-2.html"/>';
}else{
	$system_pagination = str_replace('-page-'.$_GET['page'].'.html' ,'',$monUrl);
	echo '<link rel="prev" href="'.$system_pagination.'-page-'.($_GET['page']-1).'.html"/>';
	echo '<link rel="next" href="'.$system_pagination.'-page-'.($_GET['page']+1).'.html"/>';
}
?>

</head>
<body class="category-page">
<?php include("include/header-inner.php"); ?> 
<div id="page">   
 
  <div class="breadcrumbs" itemprop="breadcrumb">
    <div class="container">
      <div class="row">
        <div class="col-xs-12">
          <ul>
          <?php
		  // Région
		  if (!empty($_REQUEST['region'])) {
          echo '<li class="home"><a href="http://lasortie.fr/sortie/region-'.simplification($_REQUEST['region']).'.html" title="sortir en '.$aRegion[$region_id].'">'.$aRegion[$region_id].'</a><span>/</span></li>';
		  }else{NULL;}
		  // Département
		  if (!empty($_REQUEST['departement'])) {
          echo '<li class="category1599"><a href="sorties-du-'.$_REQUEST['departement'].'.html" title="sortir en '.ucfirst($depts[$_REQUEST['departement']]).' ('.$_REQUEST['departement'].')">'.ucfirst($depts[$_REQUEST['departement']]).' - '.$_REQUEST['departement'].'</a><span>/ </span> </li>';
		  }else{NULL;}
		   if (!empty($_REQUEST['region']) && !empty($_REQUEST['loisir']) && empty($_REQUEST['departement']) && empty($_REQUEST['ville'])){
          echo '<li class="category1599"><a href="http://lasortie.fr/sortie/region-'.simplification($_REQUEST['region']).'/activite-'.simplification($_REQUEST['loisir']).'.html" title="'.ucfirst($_REQUEST['loisir']).' en '.$aRegion[$region_id].' ('.$_REQUEST['departement'].')">'.ucfirst($_REQUEST['loisir']).'</a><span>/ </span> </li>';
		  }else{NULL;}
		  // Loisir
		  if (!empty($_REQUEST['loisir']) && !empty($_REQUEST['region']) && !empty($_REQUEST['departement'])){
          echo '<li class="category1600"><a href="http://lasortie.fr/sortie/region-'.simplification($_REQUEST['region']).'/activite-'.simplification($_REQUEST['loisir']).'/sorties-du-'.$_REQUEST['departement'].'.html" title="'.$_REQUEST['loisir'].' en '.$aRegion[$region_id].'">'.ucfirst($_REQUEST['loisir']).'</a><span>/</span> </li>';
		  }else{NULL;}
		  if (!empty($_REQUEST['loisir']) && !empty($_REQUEST['region']) && !empty($_REQUEST['ville'])){
          echo '<li class="category1600"><a href="http://lasortie.fr/sortie/region-'.simplification($_REQUEST['region']).'/ville-de-'.simplification($_REQUEST['ville']).'/activite-'.simplification($_REQUEST['loisir']).'.html" title="'.ucfirst($_REQUEST['loisir']).' à '.ucfirst($_REQUEST['ville']).'">'.ucfirst($_REQUEST['loisir']).'</a><span>/</span> </li>';
		  }else{NULL;}
		  // ville
		  if (!empty($_REQUEST['ville'])) {
          echo '<li class="category1600"><a href="http://lasortie.fr/sortie/region-'.simplification($_REQUEST['region']).'/ville-de-'.simplification($_REQUEST['ville']).'.html" title="sortie '.ucfirst($_REQUEST['ville']).'">Sortie '.ucfirst($_REQUEST['ville']).'</a><span>/</span> </li>';
		  }else{NULL;}
		  ?>
          </ul>
        </div>  
      </div>
    </div>
</div>
     
<section class="main-container col2-left-layout">
    <div class="container">
      <div class="row">
        <div class="col-sm-9 col-sm-push-3">              
   <?php
    $path = NULL;
    if(empty($bdd)) {
        session_start();
        include("../conndb.php");
        include('variables.php');
        $path = '../';
    }
    $parPage = 15;	
	
    $du = !empty($_REQUEST['du']) ? $_REQUEST['du'] : NULL;
    $au = !empty($_REQUEST['au']) ? $_REQUEST['au'] : NULL;
    $page = !empty($_REQUEST['page']) ? $_REQUEST['page'] : 1;
	
	if(!empty($_REQUEST['datetimepicker'])) {
		$date = DateTime::createFromFormat('d/m/Y', $_REQUEST['datetimepicker']);
		$du = $au = $date->format('Y-m-d');
	}
	// On récupere le jour de la semaine en fonction de la date
	$jourRecherche = date('N', strtotime($du));	
	$_REQUEST['departement'] = !empty($_REQUEST['departement']) ? $_REQUEST['departement'] : NULL;
	$_REQUEST['departement'] = !empty($_SESSION['membre']) && empty($_REQUEST['departement']) && empty($_REQUEST['region']) ? $_SESSION['membre']['id_departements'] :$_REQUEST['departement'];
    
	
	$sql = 'SELECT * FROM loisirs JOIN `regions` ON `regions`.`region_id` = `loisirs`.`id_region` WHERE  loisirs.date_fin_sortie > NOW() AND loisirs.valide = 1';
	// region
	if(!empty($_REQUEST['region'])){
	  // FIXME : sql injectin spoted
	  $sql .= ' AND regions.url = \''.$_REQUEST['region'].'\'' ;
	}
	if(!empty($_REQUEST['departement'])){
	  $sql .=  ' AND loisirs.id_departements = '.$_REQUEST['departement'];
	}
	
	if(!empty($_REQUEST['loisir']) ){
	  // FIXME : sql injectin spoted
	  $sql .=  ' AND loisirs.genre_loisir = \''.$_REQUEST['loisir'].'\'' ; // loisir
	}
	
	// Recherche par date
	// FIXME : $du et $au n'existe pas ici ;)
	// FIXME : sql injectin spoted
	if(!empty($du) && !empty($au)) {
	  $sql .= ' AND (DATE_FORMAT(loisirs.date_debut_sortie, \'%Y-%m-%d\') <= \''.$du.'\' AND DATE_FORMAT(loisirs.date_fin_sortie, \'%Y-%m-%d\') >= \''.$au.'\')';
	}
	
	 // Recherche par ville
	if(!empty($_REQUEST['ville'])) {
	  $sql .= ' AND loisirs.city = \''. getRealValue($_REQUEST['ville']). '\'';
	}
	
	// Recherche par salle
	if(!empty($_REQUEST['manufacturer'])){
	  $sql .= ' AND loisirs.manufacturer = \''. getRealValue($_REQUEST['manufacturer'] , 'manufacturer') .'\'';
	}
	
	
	$req = $bdd->query($sql);

	// on affiche le nombre de sorties en fonction des filtres       
	$nb = $req->rowCount();
	if ($req->fetchColumn() > 0) {
		
	// on affiche le h1 en fonction de la region 
	$region_id = !empty($_REQUEST['region']) ? regionByUrl($_REQUEST['region']) : NULL; 
	$region_id = !empty($_SESSION['membre']['id_region']) && empty($_REQUEST['region']) ? $_SESSION['membre']['id_region'] : $region_id; 
	$h1 = $nb;
		
		
	// Par ville	
	$h1 .= empty($_REQUEST['ville']) && empty($_REQUEST['departement']) && empty($_REQUEST['loisir']) && empty($_REQUEST['region']) ? ' <h1 class="page-heading">annonces pour trouver une idée de sortie !</h1>' : NULL; // La ville
	$h1 .= !empty($_REQUEST['ville']) && empty($_REQUEST['departement']) && empty($_REQUEST['loisir']) && !empty($_REQUEST['region'])? ' <h1 class="page-heading"> sorties à '. ucfirst($_REQUEST['ville']).'</h1>' : NULL; // La ville
	$h1 .= !empty($_REQUEST['ville']) && !empty($_REQUEST['loisir']) && empty($_REQUEST['departement']) ? '<h1 class="page-heading">annonces pour '.ucfirst($_REQUEST['loisir']).' à '. ucfirst ($_REQUEST['ville']).' </h1>' : NULL; // La ville
	$h1 .= !empty($region_id) && empty($_REQUEST['departement']) && empty($_REQUEST['ville']) ? '<h1 class="page-heading">annonces pour sortir en ' .$aRegion[$region_id] .'</h1>': NULL; // La région
	$h1 .= !empty($_REQUEST['loisir']) &&  empty($_REQUEST['departement'])  &&  empty($_REQUEST['ville']) ? ' <h1 class="page-heading">annonces pour  ' .strtolower($_REQUEST['loisir']).'</h1>': NULL; // Le type de sortie

	// Département
	$h1 .= !empty($_REQUEST['departement']) &&  !empty($_REQUEST['loisir']) ? '<h1 class="page-heading"> des sorties ' .ucfirst($_REQUEST['loisir']).' en '.$depts[$_REQUEST['departement']].' ('.$_REQUEST['departement'].')</a></h1>' : NULL; // Le département
	$h1 .= !empty($_REQUEST['departement']) &&  !empty($_REQUEST['region']) &&  empty($_REQUEST['loisir']) &&  empty($_REQUEST['ville'])   ? '<h1 class="page-heading"> sortir en '.$depts[$_REQUEST['departement']].' ('.$_REQUEST['departement'].')</h1>' : NULL; // Le département
		
	// Affichage de la date en fr du datepicker 
	$h1 .= !empty($du) ? "  le <strong>" .date('d/m/Y', strtotime($du))."</strong>" : NULL; // La date choisis selon les filtres
	echo '<div class="col-md-12 result-search"><div class="col-md-5 pad-15"> '.$h1.'</div>'?>

	
    <!-- date -->
    <form  method="POST">
    <div class="col-md-3 col-sm-3 max">  
    <div class="input-group">
    <input class="search-motor form-control"  title="Recherche de sortie par date "id="datetimepicker2" name="datetimepicker" placeholder="Recherche par date" type="text" readonly value="<?php echo !empty($_REQUEST['datetimepicker']) ? $_REQUEST['datetimepicker'] : NULL; ?>">
    <span class="input-group-addon custom">
    <button class="btn btn-default search-btn" type="submit"><i class="fa fa-calendar-o"></i></button>
    </span>
    </div>
    </div>
    </form>
    <!-- End date -->

	<div class="col-md-4 col-sm-12 max">
    <form id="choice" method="POST" action="">
    <div class="input-group">
    <input title="Recherche par ville" placeholder="Recherche par ville" class="search-motor form-control"  value="<?php echo  !empty($_REQUEST['ville']) ? $_REQUEST['ville'] : NULL;?>" name="ville" id="ville" type="search">
    <span class="input-group-btn">
    <button name="submit_city" id="submit_city" type="submit" class="btn btn-default search-btn">GO !</button>
    </span>
    </div>
    </form>
    </div> 
      
    </div>     
    

    
<article class="col-main"> 
    <?php include("include/optimisation.php"); ?>  
    

        
    <?php echo '<div class="category-products">
    <ol class="products-list" id="products-list">'."\n";	
	}
		
	// Si il n y a que la région de demandée
	if (!empty($_REQUEST['region']) && empty($_REQUEST['loisir']) && empty($_REQUEST['departement'])  && empty($_REQUEST['ville'])){
	$valeur_paginate =  'region-'.$_REQUEST['region'];
	}
		
		// Si il y a une région de demandée et un loisir
		else if (!empty($_REQUEST['loisir']) && !empty($_REQUEST['loisir']) && empty($_REQUEST['departement']))  {
		$valeur_paginate =  'activite-'.$_REQUEST['loisir'];
		}
		
		// Si il y a une région de demandée et un loisir
		else if (!empty($_REQUEST['region']) && !empty($_REQUEST['departement']) && empty($_REQUEST['loisir'])) {
		$valeur_paginate =  'sorties-du-'.$_REQUEST['departement'];
		}
		
		// Si il y a une région de demandée et un loisir
		else if (!empty($_REQUEST['region']) && !empty($_REQUEST['departement']) && !empty($_REQUEST['loisir'])) {
		$valeur_paginate = 'sorties-du-'.$_REQUEST['departement'];
		}
		
		// Si il y a une région de demandée et un loisir
		else if (!empty($_REQUEST['region'])  && !empty($_REQUEST['loisir']) && !empty($_REQUEST['ville'])) {
		$valeur_paginate = 'sorties-du-'.$_REQUEST['departement'];
		}
		
		// Si il y a une région de demandée et un loisir
		else if (!empty($_REQUEST['region'])  && !empty($_REQUEST['ville'])) {
		$valeur_paginate = 'ville-de-'.simplification($_REQUEST['ville']);	
		}	
		?>
		<?php
		$nbre_annonces_par_page = 10;
		$nbre_pages_max_gauche_et_droite = 4;
		$last_page = ceil($nb / $nbre_annonces_par_page);
		if(isset($_GET['page']) && is_numeric($_GET['page'])){
		$page_num = $_GET['page'];
		} else {
		$page_num = 1;
		}
		if($page_num < 1){
		$page_num = 1;
		} else if($page_num > $last_page) {
		$page_num = $last_page;
		}
		$limit = 'LIMIT '.($page_num - 1) * $nbre_annonces_par_page. ',' . $nbre_annonces_par_page;
		$pagination = '';
		if($last_page != 1){
		if($page_num > 1){
		$previous = $page_num - 1;
		$pagination .= '<a href="'.$valeur_paginate.($previous > 1 ? '-page-'.$previous : null).'.html" class="page" data-page="'.$previous.'" data-du="'.$du.'" data-au="'.$au.'"><i class="fa fa-angle-left"></i></a> &nbsp; &nbsp;';
		for($i = $page_num - $nbre_pages_max_gauche_et_droite; $i < $page_num; $i++){
		if($i > 0){
		$pagination .= '<a href="'.$valeur_paginate.($i > 1 ? '-page-'.$i : null).'.html" class="page" data-page="'.$i.'" data-du="'.$du.'" data-au="'.$au.'">'.$i.'</a> &nbsp;';
		}
		}
		}
		$pagination .= '<span class="active">'.$page_num.'</span>&nbsp;';
		for($i = $page_num+1; $i <= $last_page; $i++){	
		$pagination .= '<a href="'.$valeur_paginate.'-page-'.$i.'.html" class="page" data-page="'.$i.'" data-du="'.$du.'" data-au="'.$au.'">'.$i.'</a> ';
		if($i >= $page_num + $nbre_pages_max_gauche_et_droite){
		break;
		}
		}
		if($page_num != $last_page){
		$next = $page_num + 1;
		$pagination .= '<a href="'.$valeur_paginate.'-page-'.$next.'.html" class="page" data-page="'.$next.'" data-du="'.$du.'" data-au="'.$au.'"><i class="fa fa-angle-right"></i></a> ';
		}
		}
	
		$sql .= " ORDER BY CASE
          WHEN heart = 1 THEN 3
          WHEN id_simply_user != 999 THEN 2
          WHEN id_simply_user = 999 THEN 1
          END DESC 
	 LIMIT ".intval(($page-1)*$parPage).", ".$parPage;
	 
	// echo $sql;
 
 
		$req = $bdd->query($sql);	
		
		$nb2 = $req->rowCount();
		if($nb2 > 0) {
		$req = $bdd->query($sql);
		while($ligne = $req->fetch(PDO::FETCH_ASSOC)){  
		$date = DateTime::createFromFormat('Y-m-d H:i:s', $ligne['date_debut_sortie']);      
		
		// Traitement image        
		$image = !empty($ligne['photo']) && file_exists('img/img-big-format/miniature/'.$ligne['photo']) ? 'img/img-big-format/miniature/'.$ligne['photo'] : 'img/remplacement/'.simplification($aLoisirs[$ligne['id_type_loisirs']]).'.jpg';
		
		$lien = "".$ligne["url_rewrite"]."/".$ligne["id_loisirs"];
		$dated = DateTime::createFromFormat('Y-m-d H:i:s', $ligne['date_debut_sortie']);
		$datef = DateTime::createFromFormat('Y-m-d H:i:s', $ligne['date_fin_sortie']);
		$la_variable_qui_vas_bien = "";
		if($ligne['date_debut_sortie'] != "0000-00-00 00:00:00") {
		$la_variable_qui_vas_bien = $ligne['date_debut_sortie'] = ucfirst($jour[$dated->format('N')]).' '.$dated->format('d').' '.ucfirst($mois[$dated->format('n')]).' '.$dated->format('Y');
		} else {
		$la_variable_qui_vas_bien = "Jusqu'au " .ucfirst($jour[$datef->format('N')]).' '.$datef->format('d').' '.ucfirst($mois[$datef->format('n')]).' '.$datef->format('Y');
		}
	
		$ligne['description'] = str_replace($mots, $remplacements, $ligne['description']);
		$recherche_pour_url = $ligne['titre'];
		$remplacement_url = str_replace ( ' ', '-', $recherche_pour_url);
		$salle = !empty($ligne['manufacturer']) ? $ligne['manufacturer'] : NULL;

		if (!empty ($ligne['url_fnac'])) {
		echo  '  <li class="item first">
                  <div class="product-image"><a href="http://lasortie.fr/sortie/'.$ligne["url_rewrite"]."/".simplification(strtolower($aLoisirs[$ligne["id_type_loisirs"]]))."/".simplification(strtolower($ligne["city"]))."/".$ligne["id_loisirs"].'.html"><img class="img-responsive" src="'.$ligne['photo'].'" alt="'.$ligne['titre'].' - '.ucfirst(strtolower($ligne['city'])).'" title="'.$aLoisirs[$ligne['id_type_loisirs']].', '.$ligne['titre'].' - '.ucfirst(strtolower($ligne['city'])).'"></a></div>
                  <div class="product-shop">
                    <h3 class="product-name"><a href="'.$ligne["url_rewrite"]."/".$ligne["genre_loisir"]."/".simplification($ligne["city"])."/".$ligne["id_loisirs"].'.html" title="'.ucfirst(strtolower($ligne['titre'])).'">'.ucfirst($ligne['titre']).'</a></h3>
                    <div class="ratings"><i class="fa fa-calendar-o" aria-hidden="true"></i> '.$la_variable_qui_vas_bien.'</div>
                    <div class="desc std">
                      <p>'. stripslashes(cutTexte($ligne['description'], 350, '...')).'<a class="link-learn" title="" href="/'.$lien.'"></a> </p>
                    </div>
					<p class="hash"><i class="fa fa-map-marker"></i><span class="sortir_city"> '.$salle.' - <span class="sortir_city"> <a href="http://lasortie.fr/sortie/region-'.simplification($aRegion[$region_id]).'/ville-de-'.simplification($ligne['city']).'.html"> <strong>'.ucfirst(mb_strtolower($ligne['city'], 'UTF-8')).'</strong></a></span> ('.str_pad($ligne['id_departements'], 2, "0", STR_PAD_LEFT).')</span></p>
                    <div class="actions">
                      <a href="http://lasortie.fr/sortie/'.$ligne["url_rewrite"]."/".simplification($ligne["genre_loisir"])."/".simplification(strtolower($ligne["city"]))."/".$ligne["id_loisirs"].'.html"><button class="button btn-cart ajx-cart" title="'.ucfirst(strtolower($ligne['titre'])).' à '.ucfirst(strtolower($ligne['city'])).'" type="button"><span>En détails</span></button></a>
                      <span class="add-to-links"> <a rel="nofollow" title="Add to Wishlist" class="button link-wishlist" href="/add_favoris.php?idfav='.$ligne['id_loisirs'].'"><span>Ajouter aux favoris</span></a></span> </div>              
                </div></li>'."\n";			
		}else{
			echo'  <li class="item first">
                  <div class="product-image"><a href="http://lasortie.fr/sortie/'.$ligne["url_rewrite"]."/".simplification(strtolower($aLoisirs[$ligne["id_type_loisirs"]]))."/".simplification($ligne["city"])."/".$ligne["id_loisirs"].'.html"><img class="img-responsive" src="/'.$image.'" alt="'.$ligne['titre'].' - '.ucfirst(strtolower($ligne['city'])).'" title="'.$aLoisirs[$ligne['id_type_loisirs']].', '.$ligne['titre'].' - '.ucfirst(strtolower($ligne['city'])).'"></a></div>
                  <div class="product-shop">
                    <h3 class="product-name"><a href="http://lasortie.fr/sortie/'.$ligne["url_rewrite"]."/".$ligne["genre_loisir"]."/".simplification(strtolower($ligne["city"]))."/".$ligne["id_loisirs"].'.html" title="'.ucfirst(strtolower($ligne['titre'])).'">'.ucfirst($ligne['titre']).'</a></h3>
                    <div class="ratings"><i class="fa fa-calendar-o" aria-hidden="true"></i> '.$la_variable_qui_vas_bien.'</div>
                    <div class="desc std">
                      <p>'. stripslashes(cutTexte($ligne['description'], 350, '...')).'<a class="link-learn" title="" href="/'.$lien.'"></a> </p>
                    </div>
					<p class="hash"><i class="fa fa-map-marker"></i><span class="sortir_city"><strong> <a href="http://lasortie.fr/sortie/region-'.simplification($aRegion[$region_id]).'/ville-de-'.simplification($ligne['city']).'.html"> Sortie '.ucfirst(mb_strtolower($ligne['city'], 'UTF-8')).' </a></strong> ('.str_pad($ligne['id_departements'], 2, "0", STR_PAD_LEFT).')</span></p>
                    <div class="actions">
                      <a href="http://lasortie.fr/sortie/'.$ligne["url_rewrite"]."/".simplification(strtolower($aLoisirs[$ligne["id_type_loisirs"]]))."/".simplification(mb_strtolower($ligne['city'], 'UTF-8'))."/".$ligne["id_loisirs"].'.html"><button class="button btn-cart ajx-cart" title="'.ucfirst(strtolower($ligne['titre'])).' à '.ucfirst(strtolower($ligne['city'])).'" type="button"><span>En détails</span></button></a>
                      <span class="add-to-links"> <a rel="nofollow" title="Add to Wishlist" class="button link-wishlist" href="/add_favoris.php?idfav='.$ligne['id_loisirs'].'"><span>Ajouter aux favoris</span></a></span> </div>
     
                </div></li>'."\n";	
			}	
		}
		echo '</ol><div class="pagination col-md-12">
				<div class="row">
				'.$pagination.'
				</div>
			</div>
		';
		$req->closeCursor();
		} else {
		echo  '<div class="pad15"><div class="alert alert-danger" role="alert"> <i class="fa fa-frown-o"></i>
		 Actuellement aucune sortie ne correspond à votre recherche</div></div>';
	   }   	   
?>

</div>
</article>
</div>
<div class="col-left sidebar col-sm-3 col-xs-12 col-sm-pull-9">
<div class="side-nav-categories">

<div class="block-title"> Categories </div>
<div class="dropdown-marg">
<button class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown">

<?php
			if (empty($_REQUEST['ville'])) {
				
			if (!empty($_REQUEST['departement'])){
				 echo 'Département '. $depts[$_REQUEST['departement']].'-'.$_REQUEST['departement'];
				}else{
				 echo'Choisir un département';
				}
			
			echo'
            <span class="caret"></span></button>
			<ul class="dropdown-menu">';
        	 	
				
			 	foreach($aDepartement[regionByUrl($_REQUEST['region'])] as $id => $dep){
					
				 // on affiche les sorties selon le département et le loisir demandée	
				 if (!empty($_REQUEST['region']) && empty($_GET['page']) && !empty($_REQUEST['departement']) && !empty($_REQUEST['loisir'])) {
				 echo '<li><a href="sorties-du-'.$id.'.html">'.$id.' '.$dep.'</a></li>';
				 }
				 
				    // Si il y a une page de renseignée
					else if (!empty($_REQUEST['region']) && empty($_GET['page']) && !empty($_REQUEST['departement']) && empty($_REQUEST['loisir'])) {
					echo '<li><a href="sorties-du-'.$id.'.html">'.$id.' '.$dep.'</a></li>';
					}
					
					 // Si il y a une page de renseignée
					else if (!empty($_REQUEST['region']) && !empty($_GET['page']) && empty($_REQUEST['departement']) && empty($_REQUEST['loisir'])) {
					echo '<li><a href="region-'.$_REQUEST['region'].'/sorties-du-'.$id.'.html">'.$id.' '.$dep.'</a></li>';
					}
					
					
					// Si il y a une page de renseignée
					else if (!empty($_REQUEST['region']) && !empty($_GET['page']) && empty($_REQUEST['departement']) && !empty($_REQUEST['loisir'])) {
					echo '<li><a href="sorties-du-'.$id.'.html">'.$id.' '.$dep.'</a></li>';
					}
					
					// Si il y a un département de renseignée et aucune page
					else if(empty($_GET['page']) && empty($_REQUEST['loisir']) && !empty($_REQUEST['region']) && empty($_REQUEST['departement']) && empty($_REQUEST['ville'])){
					echo '<li><a href="region-'.$_REQUEST['region'].'/sorties-du-'.$id.'.html">'.$id.' '.$dep.'</a></li>';
					}
					
					
					
					else{
					// Si il n y a pas de region de renseignée
					echo '<li><a href="sorties-du-'.$id.'.html">'.$id.' '.$dep.'</a></li>'."\n";
					}
				 
			 }
			 }else{
				echo '<h2>Sortie sur '.$_REQUEST['ville'].'</h2>';
			}
			 ?>
             </ul></div>
              <div class="box-content box-category">
                <ul>
                <?php
					// Si il n y a pas de ville de renseignée
					if (empty($_REQUEST['ville']) && empty($_REQUEST['departement']) && !empty($_REQUEST['region'])) {	
					$liste = $bdd->query("SELECT id_type_loisirs,COUNT(*) as nb FROM loisirs  WHERE id_region = ".$region_id."  AND `loisirs`.`date_fin_sortie` > NOW() AND `loisirs`.`valide` = 1 GROUP BY id_type_loisirs " );
										
					while($row = $liste->fetch(PDO::FETCH_ASSOC)) {
					$count[$row['id_type_loisirs']] =  $row['nb'];
				 	}
					asort($aLoisirs);
					foreach($aLoisirs as $k => $v) {;
					$nb = array_key_exists($k, $count) ? $count[$k] : 0;	
					if ($nb>=1) {			
					// Si il y a un loisir de renseignée et aucune page demandée
					if (!empty($_REQUEST['loisir']) && empty($_GET['page']) && empty($_REQUEST['region']) && empty($_REQUEST['departement'])) {
					echo '<li><a href="activite-'.simplification($v).'.html">'.$v.'</a><span class="subDropdown plus">'.$nb.'</span></li>'."\n";
					}
					
					// Si il y a une page de renseignée
					else if(empty($_GET['page']) && empty($_REQUEST['loisir']) && !empty($_REQUEST['ville']) && !empty($_REQUEST['region']) ) {
					echo '<li><a href="ville-de-'.simplification($_REQUEST['ville']).'/activite-'.simplification($v).'.html">'.$v.'</a><span class="subDropdown plus">'.$nb.'</span></li>'."\n";
					}
	
					// Si il y a une page de renseignée
					else if(!empty($_GET['page']) && !empty($_REQUEST['loisir'])){
					echo '<li><a href="activite-'.simplification($v).'.html">'.$v.'</a><span class="subDropdown plus">'.$nb.'</span></li>'."\n";
					}

					// Si il y a un département de renseignée et aucune page
					else if(empty($_GET['page']) && empty($_REQUEST['loisir']) && !empty($_REQUEST['region']) && empty($_REQUEST['departement'])){
					echo '<li><a href="region-'.$_REQUEST['region'].'/activite-'.simplification($v).'.html">'.$v.'</a><span class="subDropdown plus">'.$nb.'</span></li>'."\n";
					}

					// Si il y a un département de renseignée et aucune page
					else if(empty($_GET['page']) && empty($_REQUEST['loisir'])  && empty($_REQUEST['ville']) && !empty($_REQUEST['region']) && !empty($_REQUEST['departement'])){
					echo '<li><a href="activite-'.simplification($v).'/sorties-du-'.$_REQUEST['departement'].'.html">'.$v.'</a><span class="subDropdown plus">'.$nb.'</span></li>'."\n";
					}

					// Si il y a un département de renseignée et aucune page
					else if(empty($_GET['page']) && !empty($_REQUEST['loisir']) && !empty($_REQUEST['region']) && !empty($_REQUEST['departement'])){
					echo '<li><a href="../../region-'.$_REQUEST['region'].'/activite-'.simplification($v).'/sorties-du-'.$_REQUEST['departement'].'.html">'.$v.'</a><span class="subDropdown plus">'.$nb.'</span></li>'."\n";
					}

					// Si il y a un département de renseignée et aucune page
					else if(empty($_GET['page']) && !empty($_REQUEST['loisir']) && !empty($_REQUEST['region']) && empty($_REQUEST['departement'])){
					echo '<li><a href="activite-'.simplification($v).'.html">'.$v.'</a><span class="subDropdown plus">'.$nb.'</span></li>'."\n";
					}

					// Si il y a un département de renseignée et aucune page
					else if(!empty($_GET['page']) && empty($_REQUEST['loisir']) && !empty($_REQUEST['region']) && !empty($_REQUEST['departement'])){
					echo '<li><a href="activite-'.simplification($v).'/sorties-du-'.$_REQUEST['departement'].'.html">'.$v.'</a><span class="subDropdown plus">'.$nb.'</span></li>'."\n";
					}

					else{
					// Si il n y a pas de region de renseignée
					echo '<li><a href="region-'.$_REQUEST['region'].'/activite-'.simplification($v).'.html">'.$v.'</a><span class="subDropdown plus">'.$nb.'</span></li>'."\n";
					}		
				}
			}
		}
					elseif (empty($_REQUEST['ville']) && !empty($_REQUEST['departement']) && !empty($_REQUEST['region'])) {
						
					$liste = "SELECT id_type_loisirs, COUNT(id_type_loisirs) as nb FROM loisirs";
					$liste.= " WHERE id_departements = '".$_REQUEST['departement']."' AND date_fin_sortie > NOW() AND valide = 1 ";
					$liste.= " GROUP BY id_type_loisirs HAVING COUNT(id_type_loisirs) >= 1 ORDER BY nb DESC LIMIT 0,30";	
					$req = $bdd->query($liste);
					
					while($row = $req->fetch(PDO::FETCH_ASSOC)){ 
					
					if (empty($_REQUEST['ville']) && !empty($_REQUEST['departement']) && !empty($_REQUEST['region']) && empty($_REQUEST['loisir'])) {
					echo '<li><a href="../region-'.$_REQUEST['region'].'/activite-'.simplification($aLoisirs[$row['id_type_loisirs']]).'/sorties-du-'.$_REQUEST['departement'].'.html">'.$aLoisirs[$row['id_type_loisirs']].'</a><span class="subDropdown plus">'.$row['nb'].'</span></li>'."\n";
					}
					
					elseif (!empty($_REQUEST['loisir']) && !empty($_REQUEST['departement']) && !empty($_REQUEST['region']) && empty($_REQUEST['ville'])) {
					echo '<li><a href="../activite-'.simplification($aLoisirs[$row['id_type_loisirs']]).'/sorties-du-'.$_REQUEST['departement'].'.html">'.$aLoisirs[$row['id_type_loisirs']].'</a><span class="subDropdown plus">'.$row['nb'].'</span></li>'."\n";
					}
					}
					}
					else {
					$_REQUEST['ville'] = str_replace('-', ' ', $_REQUEST['ville']); // on remplace les espaces par des tirets
						
					$liste = "SELECT id_type_loisirs, COUNT(id_type_loisirs) as nb FROM loisirs";
					$liste.= " WHERE city = '".$_REQUEST['ville']."' AND date_fin_sortie > NOW() AND valide = 1 ";
					$liste.= " GROUP BY id_type_loisirs HAVING COUNT(id_type_loisirs) >= 1 ORDER BY nb DESC LIMIT 0,30";	
					$req = $bdd->query($liste);
					
					while($row = $req->fetch(PDO::FETCH_ASSOC)){ 
											
					// Si il y a un loisir de renseignée et aucune page demandée
					if (empty($_REQUEST['loisir']) && empty($_GET['page']) && !empty($_REQUEST['region']) && empty($_REQUEST['departement'])) {
					echo '<li><a href="ville-de-'.simplification($_REQUEST['ville']).'/activite-'.simplification($aLoisirs[$row['id_type_loisirs']]).'.html">'.$aLoisirs[$row['id_type_loisirs']].'</a><span class="subDropdown plus">'.$row['nb'].'</span></li>'."\n";
					}
					
					else if (!empty($_REQUEST['loisir']) && empty($_GET['page']) && !empty($_REQUEST['region']) && empty($_REQUEST['departement'])) {
					echo '<li><a href="activite-'.simplification($aLoisirs[$row['id_type_loisirs']]).'.html">'.$aLoisirs[$row['id_type_loisirs']].'</a><span class="subDropdown plus">'.$row['nb'].'</span></li>'."\n";
					}
					
					else if (empty($_REQUEST['loisir']) && !empty($_GET['page'])  && !empty($_GET['ville']) && !empty($_REQUEST['region']) && empty($_REQUEST['departement'])) {
					echo '<li><a href="ville-de-'.$_REQUEST['ville'].'/activite-'.simplification($aLoisirs[$row['id_type_loisirs']]).'.html">'.$aLoisirs[$row['id_type_loisirs']].'</a><span class="subDropdown plus">'.$row['nb'].'</span></li>'."\n";
					}
					
					// Si il y a un département de renseignée et aucune page
					else if(!empty($_GET['page']) && !empty($_REQUEST['loisir']) && !empty($_REQUEST['ville']) && !empty($_REQUEST['region'])){
					echo '<li><a href="activite-'.simplification($aLoisirs[$row['id_type_loisirs']]).'.html">'.$aLoisirs[$row['id_type_loisirs']].'</a><span class="subDropdown plus">'.$row['nb'].'</span></li>'."\n";
					}
				}
			}
			?>   
                </ul>
              </div>
            </div>
    <?php 
	$h2 = empty($_REQUEST['ville']) && empty($_REQUEST['departement']) && empty($aRegion[$region_id]) ?' <strong> activités</strong>' : NULL; // Le département
	$h2 .= !empty($_REQUEST['region']) && empty($_REQUEST['departement']) && empty($_REQUEST['ville']) ? " <strong> activités</strong> EN ".$aRegion[$region_id] : NULL; // Sortir en "nom de la région"
	
	$h2 .= !empty($_REQUEST['departement']) && empty($_REQUEST['loisir']) ? ' SORTIES '.$depts[$_REQUEST['departement']] : NULL; // Le département
	$h2 .= !empty($_REQUEST['departement']) && !empty($_REQUEST['loisir']) && empty($_REQUEST['ville']) ? '<a title="Sortie '.ucfirst($_REQUEST['loisir']).' en '.$depts[$_REQUEST['departement']].'" href="toutes-les-sorties-du-departement-'.$_REQUEST['departement'].'-'.$_REQUEST['loisir'].'.html"><strong>'.ucfirst($_REQUEST['loisir']).' <span class="normal-weight">' .$depts[$_REQUEST['departement']].'</span></strong></a>' : NULL; // Le département
	//$h2  .= !empty($_REQUEST['departement']) && !empty($_REQUEST['loisirs']) ? ' SORTIES '.$depts[$_REQUEST['departement']] : NULL; // Le département
	
	$h2 .= !empty($_REQUEST['ville']) && !empty($aRegion[$region_id]) && empty($_REQUEST['loisir'])  ?' <strong>SORTIES '.ucfirst ($_REQUEST['ville']).'</strong>' : NULL; // ville
	$h2 .= !empty($_REQUEST['departement']) && !empty($_REQUEST['loisir']) && !empty($_REQUEST['ville']) ? ucfirst($aLoisirs[$_REQUEST['loisir']]).' à ' .ucfirst ($_REQUEST['ville']) : NULL; // ville
	//$h2 .= empty($_REQUEST['departement']) && !empty($_REQUEST['loisir']) && !empty($_REQUEST['ville']) ? ucfirst($aLoisirs[$_REQUEST['loisir']]).' à ' .ucfirst ($_REQUEST['ville']) : NULL; // ville
	$h2 .= empty($_REQUEST['departement']) && !empty($aRegion[$region_id]) && !empty($_REQUEST['loisir']) && !empty($_REQUEST['ville']) ? ucfirst($_REQUEST['loisir']).' à ' .ucfirst ($_REQUEST['ville']) : NULL; // ville
	$h2 .= empty($_REQUEST['departement']) && empty($aRegion[$region_id]) && !empty($_REQUEST['loisir']) && !empty($_REQUEST['ville']) ? ucfirst($aLoisirs[$_REQUEST['loisir']]).' à ' .ucfirst ($_REQUEST['ville']) : NULL; // ville
	
	$h2 .= !empty($_REQUEST['ville']) && empty($_REQUEST['loisir']) && empty($_REQUEST['departement']) && empty($aRegion[$region_id]) ?' <strong>IDÉES DE SORTIES '.ucfirst ($_REQUEST['ville']) .'</strong>': NULL; // Le département
	echo '
 	<div class="block block-compare">
    <div class="block-title "><h2>'.$h2.'</h2></div>
    <div class="block-content">
    <ul>
	<ol id="compare-items">';?>
    <?php
	$pub = "SELECT * FROM `loisirs`  JOIN `regions` ON `regions`.`region_id` = `loisirs`.`id_region` WHERE `loisirs`.`date_fin_sortie` > NOW() AND `loisirs`.`valide` = 1";
  	$pub .= !empty($_REQUEST['region']) ? ' AND `regions`.`url` = "'.$_REQUEST['region'].'"' : NULL; // region
    $pub .= !empty($_REQUEST['departement']) ? ' AND `loisirs`.`id_departements` = '.$_REQUEST['departement'] : NULL; // dep
    $pub .= !empty($_REQUEST['loisir']) ? ' AND `loisirs`.`genre_loisir` = "'.$_REQUEST['loisir'].'"' : NULL; // loisir
	$pub .= !empty($_REQUEST['ville']) ? ' AND `loisirs`.`city` = "'.getRealValue($_REQUEST['ville']).'"' : NULL;
    $pub .= " ORDER BY RAND () DESC LIMIT 0, 10";
	$req = $bdd->query($pub);

	if($req->rowCount() > 0) {	
		
	while($ligne = $req->fetch(PDO::FETCH_ASSOC)){ 

		  if (!empty ($ligne['url_fnac'])) {  
		  echo '<li class="item odd"><a rel="nofollow" href="'.$ligne["url_rewrite"]."/".$ligne["genre_loisir"]."/".simplification(strtolower($ligne["city"]))."/".$ligne["id_loisirs"].'.html" class="product-name">'. ucfirst(cutTexte($ligne['titre'], 40, '...')).'</a><div class="adjust-titre"></div></li>';	     
		  }else{
		  echo '<li class="item odd"><a rel="nofollow" href="'.$ligne["url_rewrite"]."/".$ligne["genre_loisir"]."/".simplification(strtolower($ligne["city"]))."/".$ligne["id_loisirs"].'.html" class="product-name"> '. ucfirst(cutTexte($ligne['titre'], 40, '...')).'</a><div class="adjust-titre"> </div></li>';
			}
		  }
		}   
	 ?>	
	</ol>
</ul>
   </div></div>
    
            <div class="block block-tags">
               <div class="block-title"> VILLES ACTIVES <?php if (!empty($_REQUEST['region']) && empty($_REQUEST['departement']) && empty($_REQUEST['ville'])) { echo $aRegion[$region_id]; }?>
              </div>
              <div class="block-content">
                <ul>    
                 <?php
				$actu_ville = "SELECT DISTINCT city, count(*) as nb_annonces FROM `loisirs`  JOIN `regions` ON `regions`.`region_id` = `loisirs`.`id_region`";
				$actu_ville .= !empty($_REQUEST['region']) ? ' AND `regions`.`url` = "'.$_REQUEST['region'].'"' : NULL;
				$actu_ville .= !empty($_REQUEST['departement']) ? ' AND `loisirs`.`id_departements` = '.$_REQUEST['departement'] : NULL;
				$actu_ville .= !empty($_REQUEST['loisir']) ? ' AND `loisirs`.`id_type_loisirs` = "'.$_REQUEST['loisir'].'"' : NULL;
				$actu_ville .= !empty($_REQUEST['ville']) ? ' AND `loisirs`.`city` = "'.getRealValue($_REQUEST['ville']).'"' : NULL;
				$actu_ville .= " GROUP BY city HAVING nb_annonces >10 ORDER BY nb_annonces DESC LIMIT 0,15";
				$req = $bdd->query($actu_ville);
				$nb_annonces = $req->rowCount();
				if($req->rowCount() > 0) {
						 
				while($recent_actu = $req->fetch(PDO::FETCH_ASSOC)){    

				if (empty($_REQUEST['loisir']) && empty($_GET['page']) && !empty($_REQUEST['region']) && empty($_REQUEST['departement']) && empty($_REQUEST['ville'])) {
				echo '<li><a class="follow_actu_sortie" href="region-'.$_REQUEST['region'].'/ville-de-'.simplification($recent_actu['city']).'.html">Sortir à '.ucfirst(mb_strtolower($recent_actu['city'], 'UTF-8')).'</a></li>';
				}
				elseif (empty($_REQUEST['loisir']) && !empty($_GET['page']) && !empty($_REQUEST['region']) && empty($_REQUEST['departement']) && empty($_REQUEST['ville'])) {
				echo '<li><a class="follow_actu_sortie" href="region-'.$_REQUEST['region'].'/ville-de-'.simplification($recent_actu['city']).'.html">Sortir à '.ucfirst(mb_strtolower($recent_actu['city'], 'UTF-8')).'</a></li>';
				}
				
				else {
				echo '<li><a class="follow_actu_sortie" href="ville-de-'.simplification($recent_actu['city']).'.html">Sortir à '.ucfirst(mb_strtolower($recent_actu['city'], 'UTF-8')).'</a></li>';
				  }
				}
				    
				}else{ echo 'Aucune annonce enregistrée '; } 
				?>   
                </ul>
              </div>
        </div>
    </div>
    </div>
    </div>
    
  </section>
<?php include("include/footer-inner.php"); ?>
<script type="text/javascript" src="/js/jquery.min.js"></script> 
<script async type="text/javascript" src="/js/bootstrap.min.js"></script>  
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>


<script type="text/javascript" src="/js/jquery.datetimepicker-min.js"></script>
<script async type="text/javascript" src="/js/moment.js"></script>
<script async type="text/javascript">
				jQuery('#datetimepicker2').datetimepicker({
				  datepicker:true,
				   timepicker:false,
				   closeOnDateSelect:true,
				  format:'d/m/Y'
				});
			</script>
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
<link href='https://fonts.googleapis.com/css?family=Raleway:400,300,600,500,700,800' rel='stylesheet' type='text/css'>

<link rel="stylesheet" type="text/css" href="/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="/css/style.css" media="all">
<link rel="stylesheet" href="/css/jquery.datetimepicker.css">
</body>
</html>

Re: Optimiser mes requetes

par Ryle » 21 juil. 2016, 17:03

Bonjour,

Effectivement, les performances peuvent être optimisées (et mises en péril) à différent niveau... ça peut être le temps d'exécution des requêtes, les redondances de code, des allocations de mémoire superflue... c'est souvent des pouièmes à grappiller, mais à force ça peut commencer à faire.

A voir effectivement pour supprimer si tu as des requêtes inutiles, des jointures qui ne servent à rien, des données que tu lis mais n'utilise pas.. et si tu peux ajouter des clés et des index pour faciliter les recherches, tu peux sans doute optimiser tes requêtes... mais il n'y a peut être plus rien à faire de ce côté là. A voir en fonction de ton code et de ton architecture :)

Optimiser mes requetes

par yoann38 » 21 juil. 2016, 16:45

Salut à tous.
Ma question est d'ordre SEO et PHP.
Donc je pense qu'elle va intéressé pas mal de personne car un site c'est bien mais sil est pas efficace ça sert à rien.
Donc mon site est finis et je cherche à améliorer le temps de chargement de celui ci surtout une page que je trouve long a charger à savoir 1.2 seconde d'après:
https://developers.google.com/speed/pa ... oble.html

Vu que je ne suis pas pro PHP.
Je pense que je fait des requetes soit trop complexe pour être suffisament rapide soit inutile.
Est ce que ces fameuse requete ralenti l'affichage d'un site déjà ou uniquement le html généré.

Je peut poster mon code de cette page si besoin est.
Merci à vous