Page 1 sur 1

Défilement de photos selon recherche

Posté : 11 sept. 2015, 11:07
par DEVILLERS
Bonjour,
J'ai récupérer un script de petite annonces, dans l'interface il y a trois onglets principaux un 'accueil', un 'recherche' et un autre 'offres'.
Il y a au-dessus des onglets un bloc avec 5 images premiums que l'on peut faire défiler d'un coup en cliquant à nouveau sur l'onglet de la page concernée.
On peut aussi faire des recherches par 'région' ou encore 'catégorie' ou 'recherche par mot' ou encore par code postal.
Image

J'ai réussi à intégrer un petit script en javascript pour rafraichir la page Accueil ou annonce par exemple pour faire défiler les photos dans la barre prémium. Il y a une flèche droite avec du texte suivant.

Exemple pour rafraîchir la page des offres, fleche.js appelé dans le <head> du fichier functions_html.php :

fleche.js

Code : Tout sélectionner

var monurl = document.URL ; if( monurl == 'http://www.test.fr/annonce/ann_type.php?type=1'){ document.write("<div class='flecheslider'onClick=\"window.location.href='http://www.test.fr/annonce/ann_type.php?type=1'\">Suivant</div>"); }

Mais seulement voilà je désespère car je voudrais le même principe pour une recherche selon une région sélectionnée (bloc vert en bas à droite) par exemple, j'ai bien une URL mais quelle URL, elle est codée. Et pour faire défiler les annonces premiums il faut re-cliquer sur le bouton recherche pas très ergonomique pour moi.
Non, la solution au problème serait d'afficher le bouton du slider selon le résultat de la recherche sous forme de requète.
Pouvez-vous m'apporter quelques conseils pour réaliser cette opération ou comment dois-je procéder?
Le code est un peut long désolé.
Merci pour vos réponses.
extrait de functions_html.php

Code : Tout sélectionner

<?php /// ----- HEADER ACCUEIL ----- /// function htm_header_acc($title, $description, $words) { global $language, $param_gen, $cache_publicites, $cache_nombre_annonce; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr-FR" lang="fr-FR"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title><?php if(!empty($title)) echo $title; ?></title> <meta name="Description" content="<?php if (!empty($description)) echo $description; ?>" /> <meta name="Keywords" lang="fr" content="<?php if (!empty($words)) echo $words; ?>" /> <meta name="Robots" content="all" /> <link href="style/structure.css" type="text/css" rel="stylesheet" /> <link href="style/style.css" type="text/css" rel="stylesheet" /> <link href="includes/map/style_map.css" type="text/css" rel="stylesheet" /> </head> <body> <div id="top_header"> <div id="menu_top_header"> <ul id="left_top_header"> <?php if(empty($_SESSION['connect'])) { if($param_gen['actif_acc'] == 2 || $param_gen['actif_acc'] == 3) echo '<li class="li_top_header"><img src="images/top_header_fl.png" alt="" /><a href="acc_conn.php?type=1">'. $language['lien_compte'] .'</a></li>'; if($param_gen['actif_acc'] > 1) echo '<li class="li_top_header"><img src="images/top_header_fl.png" alt="" /><a href="acc_conn.php?type=2">'. $language['lien_compte_pro'] .'</a></li>'; } else { echo '<li class="li_top_header">'. $language['lien_bienvenue'] .' '. $_SESSION['prenom'] .'</li>'; echo '<li class="li_top_header"><img src="images/top_header_fl.png" alt="" /><a href="acc_bord.php">'. $language['compte_lien_bord1'] .'</a></li>'; echo '<li class="li_top_header"><img src="images/top_header_fl.png" alt="" /><a href="acc_logout.php">'. $language['compte_lien_bord5'] .'</a></li>'; } ?> </ul> <div id="right_top_header"> <p id="p_top_header"><span class="vert_1"><?php echo $cache_nombre_annonce['total']; ?></span> <?php echo $language['nombre_annonce']; ?></p> </div> </div> </div> <?php $image = ''; $url = ''; foreach($cache_publicites as $v) { if($v['type'] == 4) { $image = stripslashes(htmlspecialchars($v['image'], ENT_QUOTES)); $url = stripslashes(htmlspecialchars($v['url'], ENT_QUOTES)); } } if(!empty($image)) echo '<a id="fond" style=\'background: url("images/pub/'. $image .'") center top;\' href="'. $url .'" onclick="window.open(this.href); return false;"></a><a href="'. $url .'"><p style="height: 170px;"></p></a>'; ?> <div id="fond_site_1"> <div id="fond_site_2"> <?php if(is_dir('install')) echo '<div><span class="error">'. $language['error_install_file'] .'</span></div>'; if(is_dir('admin')) echo '<div><span class="error">'. $language['error_admin_file'] .'</span></div>'; if(is_dir('cron')) echo '<div><span class="error">'. $language['error_cron_file'] .'</span></div>'; ?> <div id="haut_site"> <div id="haut_site_logo"> <p><a href="<?php echo URL; ?>"><img src="images/logo.png" alt="<?php if(!empty($title)) echo stripslashes(htmlspecialchars($title, ENT_QUOTES)); ?>" /></a></p> </div> <div id="haut_site_pub"> <?php $image = ''; $url = ''; $script = ''; foreach($cache_publicites as $v) { if($v['id_pub'] == 1) { $image = stripslashes(htmlspecialchars($v['image'], ENT_QUOTES)); $url = stripslashes(htmlspecialchars($v['url'], ENT_QUOTES)); $script = $v['script']; } } if (!empty($script)) echo $script; else echo '<p><a href="'. $url .'" onclick="window.open(this.href); return false;"><img src="images/pub/'. $image .'" alt="" /></a></p>'; ?> </div> </div> <div id="barre_liens_fond"> <div id="barre_liens"> <ul class="ul_barre"> <li class="li_barre"><a href="<?php echo URL; ?>"><?php echo $language['lien_accueil']; ?></a></li> <li class="li_barre"><strong><a href="ann_type.php?type=1"><?php echo $language['lien_offres']; ?></a></strong></li> <li class="li_barre"><a href="ann_type.php?type=2"><?php echo $language['lien_recherches']; ?></a></li> <?php if($param_gen['active_ech'] == 1) echo '<li class="li_barre"><a href="ann_type.php?type=3">'. $language['lien_echanges'] .'</a></li>'; ?> <?php if($param_gen['active_don'] == 1) echo '<li class="li_barre"><a href="ann_type.php?type=4">'. $language['lien_dons'] .'</a></li>'; ?> <?php if($param_gen['actif_acc'] > 1 && $param_gen['active_bout'] == 1) echo '<li class="li_barre"><a href="boutiques_search.php">'. $language['lien_boutiques'] .'</a></li>'; ?> </ul> </div> <div id="barre_liens_depot"> <a href="<?php if($param_gen['actif_acc'] == 2 && !isset($_SESSION['connect'])) echo 'acc_info.php'; else echo 'deposer-une-annonce.htm'; ?>"><img src="images/bouton_depot.png" alt="" /></a> </div> </div> <?php } /// ----- HEADER PRINCIPAL ----- /// function htm_header($title, $description, $words) { global $language, $param_gen, $cache_publicites, $cache_nombre_annonce, $param_gen; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr-FR" lang="fr-FR"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title><?php if(!empty($title)) echo htmlspecialchars($title); ?></title> <meta name="Description" content="<?php if (!empty($description)) echo htmlspecialchars($description); ?>" /> <meta name="Keywords" lang="fr" content="<?php if (!empty($words)) echo $words; ?>" /> <meta name="Robots" content="all" /> <link href="style/structure.css" type="text/css" rel="stylesheet" /> <link href="style/style.css" type="text/css" rel="stylesheet" /> <script type="text/javascript"> function autoCompOff(){ var nodeList = document.getElementsByTagName("input"); for(item in nodeList) { nodeList[item].setAttribute("autocomplete","off"); }; } window.onload = function(){ if((navigator.userAgent.toLowerCase().match('safari')) || (navigator.userAgent.toLowerCase().match('chrome'))){ autoCompOff(); } }; </script> </head> <body> <div id="top_header"> <div id="menu_top_header"> <ul id="left_top_header"> <?php if(empty($_SESSION['connect'])) { if($param_gen['actif_acc'] == 2 || $param_gen['actif_acc'] == 3) echo '<li class="li_top_header"><img src="images/top_header_fl.png" alt="" /><a href="acc_conn.php?type=1">'. $language['lien_compte'] .'</a></li>'; if($param_gen['actif_acc'] > 1) echo '<li class="li_top_header"><img src="images/top_header_fl.png" alt="" /><a href="acc_conn.php?type=2">'. $language['lien_compte_pro'] .'</a></li>'; } else { echo '<li class="li_top_header">'. $language['lien_bienvenue'] .' '. $_SESSION['prenom'] .'</li>'; echo '<li class="li_top_header"><img src="images/top_header_fl.png" alt="" /><a href="acc_bord.php">'. $language['compte_lien_bord1'] .'</a></li>'; echo '<li class="li_top_header"><img src="images/top_header_fl.png" alt="" /><a href="acc_logout.php">'. $language['compte_lien_bord5'] .'</a></li>'; } ?> </ul> <div id="right_top_header"> <p id="p_top_header"><span class="vert_1"><?php echo $cache_nombre_annonce['total']; ?></span> <?php echo $language['nombre_annonce']; ?></p> </div> </div> </div> <?php $image = ''; $url = ''; foreach($cache_publicites as $v) { if($v['type'] == 4) { $image = stripslashes(htmlspecialchars($v['image'], ENT_QUOTES)); $url = stripslashes(htmlspecialchars($v['url'], ENT_QUOTES)); } } if(!empty($image)) echo '<a id="fond" style=\'background: url("images/pub/'. $image .'") center top;\' href="'. $url .'" onclick="window.open(this.href); return false;"></a><a href="'. $url .'"><p style="height: 170px;"></p></a>'; ?> <div id="fond_site_1"> <div id="fond_site_2"> <?php if(is_dir('install')) echo '<div><span class="error">'. $language['error_install_file'] .'</span></div>'; if(is_dir('admin')) echo '<div><span class="error">'. $language['error_admin_file'] .'</span></div>'; if(is_dir('cron')) echo '<div><span class="error">'. $language['error_cron_file'] .'</span></div>'; ?> <div id="haut_site"> <div id="haut_site_logo"> <p><a href="<?php echo URL; ?>"><img src="images/logo.png" alt="<?php if(!empty($param_gen['name'])) echo stripslashes(htmlspecialchars($param_gen['name'], ENT_QUOTES)); ?>" /></a></p> </div> <div id="haut_site_pub"> <?php $image = ''; $url = ''; $script = ''; foreach($cache_publicites as $v) { if($v['id_pub'] == 1) { $image = stripslashes(htmlspecialchars($v['image'], ENT_QUOTES)); $url = stripslashes(htmlspecialchars($v['url'], ENT_QUOTES)); $script = $v['script']; } } if (!empty($script)) echo $script; else echo '<p><a href="'. $url .'" onclick="window.open(this.href); return false;"><img src="images/pub/'. $image .'" alt="" /></a></p>'; ?> </div> </div> <div id="barre_liens_fond"> <div id="barre_liens"> <ul class="ul_barre"> <li class="li_barre"><a href="<?php echo URL; ?>"><?php echo $language['lien_accueil']; ?></a></li> <li class="li_barre"><strong><a href="ann_type.php?type=1"><?php echo $language['lien_offres']; ?></a></strong></li> <li class="li_barre"><a href="ann_type.php?type=2"><?php echo $language['lien_recherches']; ?></a></li> <?php if($param_gen['active_ech'] == 1) echo '<li class="li_barre"><a href="ann_type.php?type=3">'. $language['lien_echanges'] .'</a></li>'; ?> <?php if($param_gen['active_don'] == 1) echo '<li class="li_barre"><a href="ann_type.php?type=4">'. $language['lien_dons'] .'</a></li>'; ?> <?php if($param_gen['actif_acc'] > 1 && $param_gen['active_bout'] == 1) echo '<li class="li_barre"><a href="boutiques_search.php">'. $language['lien_boutiques'] .'</a></li>'; ?> </ul> </div> <div id="barre_liens_depot"> <a href="<?php if($param_gen['actif_acc'] == 2 && !isset($_SESSION['connect'])) echo 'acc_info.php'; else echo 'deposer-une-annonce.htm'; ?>"><img src="images/bouton_depot.png" alt="" /></a> </div> </div> <!----------------fleche----------------------------------------> <script type='text/javascript' language='javascript' src='/annonce/fleche.js'></script> <?php } /// ----- ANNONCES PREMIUM ----- /// function htm_top_ads($array) { global $language, $param_gen, $cache_regions, $cache_departements, $cache_categories; ?> <div id="menu_an_premium"> <?php if(is_array($array)) { foreach ($array as $row) { $id = (int) $row['id_ann']; $titre = stripslashes(htmlspecialchars($row['titre'])); $prix = (float) $row['prix']; $prix = number_format($prix, 2, ',', ' '); $id_reg = (int) $row['id_reg']; $id_dep = (int) $row['id_dep']; $id_cat = (int) $row['id_cat']; $nom_reg = ''; $nom_dep = ''; $nom_cat = ''; $disc = ''; foreach($cache_regions as $v) { if($id_reg == $v['id_reg']) $nom_reg = stripslashes(htmlspecialchars($v['nom_reg'], ENT_QUOTES)); } foreach($cache_departements as $v) { if($id_dep == $v['id_dep']) $nom_dep = stripslashes(htmlspecialchars($v['nom_dep'], ENT_QUOTES)); } foreach($cache_categories as $v) { if($id_cat == $v['id_cat']) { $nom_cat = stripslashes(htmlspecialchars($v['nom_cat'], ENT_QUOTES)); $disc = (int) $v['disc']; } } $nom_image = stripslashes(htmlspecialchars($row['nom_image'], ENT_QUOTES)); // Url rewriting $accent = array('à', 'á', 'â', 'ã', 'ä', 'å', 'À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'ç', 'Ç', 'é', 'è', 'ê', 'ë', 'È', 'É', 'Ê', 'Ë', 'ì', 'í', 'î', 'ï', 'Ì', 'Í', 'Î', 'Ï', 'ò', 'ó', 'ô', 'õ', 'ö', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'ù', 'ú', 'û', 'ü', 'Ú', 'Ù', 'Û', 'Ü', 'Ý', 'ý', 'ÿ', 'ñ', '''); $sans_accent = array('a', 'a', 'a', 'a', 'a', 'a', 'A', 'A', 'A', 'A', 'A', 'A', 'c', 'C', 'e', 'e', 'e', 'e', 'E', 'E', 'E', 'E', 'i', 'i', 'i', 'i', 'I', 'I', 'I', 'I', 'o', 'o', 'o', 'o', 'o', 'O', 'O', 'O', 'O', 'O', 'u', 'u', 'u', 'u', 'U', 'U', 'U', 'U', 'y', 'y', 'y', 'n', ''); $url_ann = $nom_reg .'-'. $nom_dep .'-'. $nom_cat .'-'. $titre; $url_ann = str_replace($accent, $sans_accent, $url_ann); $url = array(); for ($i = 0; $i < strlen($url_ann); $i++) array_push($url, $url_ann[$i]); $url_aff = ''; foreach($url as $url_ann) { if(preg_match('#^[a-zA-Z0-9]$#', $url_ann) != true) $url_ann = str_replace($url_ann, '-', $url_ann); $url_aff .= $url_ann; } // Taille du titre if (strlen($titre) > 21) { $titre = substr($titre, 0, 21); $pos = strrpos($titre, ' '); if($pos) $titre = substr($titre, 0, $pos); $titre .= "..."; } if($disc == 0 || isset($_SESSION['disc'])) { ?> <div class="fond_ann_premium"> <?php //////////////////////////////////////modif taille vignette avant : width;100* heigth:70////////////////////////////////////////////////////// echo '<div class="bloc_photo_premium">'; if(!empty($nom_image) && preg_match('#^https?://#', $nom_image) == true) { echo '<a href ="'. $url_aff .'-'. $id .'.htm"><img src="'. $nom_image .'" style="max-width: 160px; max-height:120px;" alt="" /></a>'; } elseif(!empty($nom_image) && file_exists('images/vignettes/'. $nom_image)) { $size = getimagesize('images/vignettes/'. $nom_image); if($size[0] < 160 && $size[1] < 120) echo '<a href="'. $url_aff .'-'. $id .'.htm"><img src="images/vignettes/'. $nom_image .'" alt="" /></a>'; elseif($size[0] > $size[1]) echo '<a href ="'. $url_aff .'-'. $id .'.htm"><img src="images/vignettes/'. $nom_image .'" width="160" height="120" alt="" /></a>'; elseif($size[0] <= $size[1]) echo '<a href ="'. $url_aff .'-'. $id .'.htm"><img src="images/vignettes/'. $nom_image .'" height="160" alt="" /></a>'; } else echo '<a href ="'. $url_aff .'-'. $id .'.htm"><img src="images/no_photo1.png" alt="" /></a>'; echo '</div>'; echo '<div class="bloc_titre_premium">'; echo '<p><a href="'. $url_aff .'-'. $id .'.htm" class="lien_titre_premium">'. $titre .'</a><br /><span class="txt_info_premium">'; if(empty($nom_dep)) //echo $sexe .'<br /></span>'; echo $nom_reg .'<br /></span>'; else echo $nom_dep .'<br /></span>'; if($prix != 0) echo '<span class="prix_premium"><strong>'. $prix .' '. $param_gen['devise'] .'</strong></span></p>'; else echo '<span class="prix_premium"><strong>'. $language['no_prix'] .'</strong></span></p>'; echo '</div>'; ?> </div> <?php } else { ?> <div class="fond_ann_premium"> <p class="p_disc_ads txt_info"><?php echo $language['texte_disc']; ?></p> <form method="post" action=""> <input type="hidden" name="disc" value="1" /> <input type="image" src="images/bouton_majeur.png" alt="" /> </form> </div> <?php } } } for($count_ann = count($array); $count_ann < 5; $count_ann++) { ?> <div class="fond_ann_premium"> <p class="p_no_premium vert"> <?php echo $language['txt_premium']; ?> </p> <p style="padding-top: 3px;"> <img src="images/fleche.png" alt="" /><a href="javascript:;" onclick="window.open('plus_premium.php', 'PREMIUM', 'scrollbars = no, width = 560, height = 360')" class="lien_plus_premium violet_1"><?php echo $language['lien_premium']; ?></a> </p> </div> <?php } ?> </div> <?php }
functions_search.php

Code : Tout sélectionner

<?php ############################################################ /////////////////////////////////// //Afficher les régions ////////////////////////////////// function display_search_regions($id, $regions) { global $language; echo '<select id="dep" name="reg" class="select_recherche" onchange="GetDepartements()">'; echo '<option value="0">'. $language['select_regions'] .'</option>'; foreach ($regions as $row) { $id_reg = (int) $row['id_reg']; $nom_reg = stripslashes(htmlspecialchars($row['nom_reg'], ENT_QUOTES)); if ($id_reg == $id) echo '<option value="'. $id_reg .'" selected="selected">'. $nom_reg .'</option>'; else echo '<option value="'. $id_reg .'">'. $nom_reg .'</option>'; } echo '</select>'; } /////////////////////////////////// //Afficher les départements ////////////////////////////////// function display_search_departements($id, $reg, $departements) { global $language; echo '<select name="dep" class="select_recherche">'; echo '<option value="0">'. $language['select_departements'] .'</option>'; foreach ($departements as $row) { $id_dep = (int) $row['id_dep']; $id_reg = (int) $row['id_reg']; $nom_dep = stripslashes(htmlspecialchars($row['nom_dep'], ENT_QUOTES)); if($id_reg == $reg) { if ($id_dep == $id) echo '<option value="'. $id_dep .'" selected="selected">'. $nom_dep.'</option>'; else echo '<option value="'. $id_dep .'">'. $nom_dep .'</option>'; } } echo '</select>'; } /////////////////////////////////// //Afficher les categories ////////////////////////////////// function display_search_categories($id, $categories) { global $language; echo '<select id="opt" name="cat" class="select_recherche" onchange="GetOptions()">'; echo '<option value="0">'. $language['select_categories'] .'</option>'; foreach($categories as $row) { $id_cat = (int) $row['id_cat']; $par_cat = (int) $row['par_cat']; $name_cat = stripslashes(htmlspecialchars($row['nom_cat'], ENT_QUOTES)); if($par_cat == 0) { if(!empty($id) && $id == $name_cat) echo '<option value="'. $name_cat .'" class="fond_select_categories uppercase" selected="selected">-- '. strtoupper($name_cat) .' --</option>'; else echo '<option value="'. $name_cat .'" class="fond_select_categories uppercase">-- '. strtoupper($name_cat) .' --</option>'; } //Sous catégories $sous_categories = $categories; foreach($sous_categories as $row) { $id_sous_cat = (int) $row['id_cat']; $par_sous_cat = (int) $row['par_cat']; $name_sous_cat = stripslashes(htmlspecialchars($row['nom_cat'], ENT_QUOTES)); if($par_sous_cat == $id_cat) { if($id_sous_cat == $id) echo '<option value="'. $id_sous_cat .'" selected="selected">'. $name_sous_cat .'</option>'; else echo '<option value="'. $id_sous_cat .'">'. $name_sous_cat .'</option>'; } } } echo '</select>'; } /////////////////////////////////// //Afficher les options de recherche ////////////////////////////////// function display_search_options($id) { global $language, $cache_search_valeurs, $cache_search_donnees, $cache_search_checkbox; echo '<div id="option">'; display_select($id, $cache_search_valeurs); display_select($id, $cache_search_donnees); display_select($id, $cache_search_checkbox); echo '</div>'; } /////////////////////////////////// //Afficher les options select ////////////////////////////////// function display_select($id, $array) { global $cache_select_valeurs, $cache_select_donnees, $cache_select_checkbox, $cache_options_cat; $i = 1; $c = 1; $num = 1; foreach ($array as $v) { foreach($cache_options_cat as $o) { if($v['id_opt'] == $o['id_opt']) $type = $o['type']; } if($num%2) { $num = 1; } else $num = 2; $id_sea = (int) $v['id_sea']; $id_cat = (int) $v['id_cat']; $sel_nom = stripslashes(htmlspecialchars($v['sel_nom'], ENT_QUOTES)); $id_opt = (int) $v['id_opt']; if($id == $id_cat) { if(!isset($type) || $type != 3) { echo '<select name="sel'. $id_opt .'_'. $num .'" class="select_recherche">'; echo '<option value="0">'. $sel_nom .'</option>'; $valeurs = $cache_select_valeurs; foreach($valeurs as $row) { $sel_nom_val = stripslashes(htmlspecialchars($row['sel_nom'], ENT_QUOTES)); $v = stripslashes(htmlspecialchars($row['valeur'] , ENT_QUOTES)); if($sel_nom == $sel_nom_val) { if(isset($_SESSION['search']['sel'. $id_opt .'_'. $num]) && $_SESSION['search']['sel'. $id_opt .'_'. $num] != 0 && $_SESSION['search']['sel'. $id_opt .'_'. $num] == $v) echo '<option value="'. $v .'" selected="selected">'. $v .'</option>'; else echo '<option value="'. $v .'">'. $v .'</option>'; } } $valeurs = $cache_select_donnees; foreach($valeurs as $row) { $v = stripslashes(htmlspecialchars($row['valeur'] , ENT_QUOTES)); $id_opt_don = (int) $row['id_opt']; if($id_opt == $id_opt_don) { if(isset($_SESSION['search']['sel'. $id_opt .'_'. $num]) && $_SESSION['search']['sel'. $id_opt .'_'. $num] != '0' && $_SESSION['search']['sel'. $id_opt .'_'. $num] == $v) echo '<option value="'. $v .'" selected="selected">'. $v .'</option>'; else echo '<option value="'. $v .'">'. $v .'</option>'; } } echo "</select>"; } else { $valeurs = $cache_select_checkbox; $num_check = 1; echo '<div class="title_checkbox"><p class="p_recherche_unique"><img src="images/fleche_u.png" alt="" />'. $sel_nom .'</p></div><div id="left_checkbox_recherche">'; foreach($valeurs as $row) { $v = stripslashes(htmlspecialchars($row['valeur'] , ENT_QUOTES)); $id_opt_check = (int) $row['id_opt']; if($id_opt == $id_opt_check) { ?> <p class="p_checkbox_recherche"> <input type="checkbox" class="input_checkbox" id="<?php echo $v; ?>" name="<?php echo 'sel'. $id_opt .'_'. $num_check; ?>" value="<?php echo $v; ?>" onclick="turnImgCheck(this);" <?php if (!empty($_SESSION['search']['sel'. $id_opt .'_'. $num_check])) echo 'checked="checked"'; ?> /> <img <?php if (!empty($_SESSION['search']['sel'. $id_opt .'_'. $num_check])) echo 'src="images/check2.png"'; else echo 'src="images/check1.png"'; ?> id="img_check_<?php echo $v; ?>" alt="" /> &nbsp;<label for="<?php echo $v; ?>"><?php echo $v; ?></label> </p> <?php //if(isset($_SESSION['search']['sel'. $id_opt .'_'. $num]) && $_SESSION['search']['sel'. $id_opt .'_'. $num] != '0' && $_SESSION['search']['sel'. $id_opt .'_'. $num] == $v) //echo '<option value="'. $v .'" selected="selected">'. $v .'</option>'; //else echo '<option value="'. $v .'">'. $v .'</option>'; $num_check++; } } echo '</div>'; } $i++; $c++; $num++; } } }
enfin un bout de code de functions_mysql.php

Code : Tout sélectionner

/////////////////// //Obtenir le nombre d'annonce du vendeur /////////////////// function get_nb_annonce_vendeur($id, $tri) { global $conn; $bdd = $conn; $prix_req = ($tri == 2) ? " AND s.prix > :prix" : ""; $sql = "SELECT count(*) AS total FROM ". PREFIX ."annonces_search s LEFT JOIN ". PREFIX ."annonces a ON s.id_ann = a.id_ann WHERE a.email = (SELECT email FROM ". PREFIX ."annonces WHERE id_ann = :id_ann) AND s.etat = :etat". $prix_req; $req = $bdd->prepare($sql); $req->bindValue('id_ann', $id, PDO::PARAM_INT); $req->bindValue('etat', 2, PDO::PARAM_INT); if($tri == 2) $req->bindValue('prix', 0, PDO::PARAM_INT); $req->execute(); $result = $req->fetch(); $req->closeCursor(); return $result; } /////////////////// //Obtenir les annonces d'un vendeur /////////////////// function get_all_vendeur($id, $offset, $limit, $tri) { global $conn; $bdd = $conn; $prix_req = ($tri == 2) ? " AND s.prix > :prix" : ""; $order_req = ($tri == 2) ? " ORDER BY s.prix ASC" : " ORDER BY s.date DESC"; $sql = "SELECT s.id_ann, s.id_reg, s.id_dep, s.id_cat, s.code_pos, s.status, s.type, s.titre, s.ann, s.prix, s.date, s.urg, o.enc, a.nom, a.ville, a.n_photo, i.nom AS nom_image, v.video FROM ". PREFIX ."annonces_search s LEFT JOIN ". PREFIX ."annonces a ON s.id_ann = a.id_ann LEFT JOIN ". PREFIX ."annonces_images i ON s.id_ann = i.id_ann AND i.id_ima = (SELECT MIN(id_ima) FROM ". PREFIX ."annonces_images WHERE id_ann = s.id_ann) LEFT JOIN ". PREFIX ."annonces_options o ON s.id_ann = o.id_ann LEFT JOIN ". PREFIX ."annonces_video v ON s.id_ann = v.id_ann WHERE s.etat = :etat AND a.email = (SELECT email FROM ". PREFIX ."annonces WHERE id_ann = :id_ann) ". $prix_req . $order_req ." LIMIT :offset, :limit"; $req = $bdd->prepare($sql); $req->bindValue('etat', 2, PDO::PARAM_INT); if($tri == 2) $req->bindValue('prix', 0, PDO::PARAM_INT); $req->bindValue('id_ann', $id, PDO::PARAM_INT); $req->bindValue('offset', $offset, PDO::PARAM_INT); $req->bindValue('limit', $limit, PDO::PARAM_INT); $req->execute(); $result = result_to_array($req); return $result; } //////////////////////////////// //Obtenir le nombre d'annonce total, particulier ou professionnel d'une région //////////////////////////////// function get_nb_annonce_reg($id, $tri) { global $conn; $bdd = $conn; $prix_req = ($tri == 2) ? " AND prix > :prix" : ""; $sql = "SELECT (SELECT COUNT(status) FROM ". PREFIX ."annonces_search WHERE etat = :etat AND status = :status_par AND id_reg = :id_reg". $prix_req .") as count_par, (SELECT COUNT(status) FROM ". PREFIX ."annonces_search WHERE etat = :etat AND status = :status_pro AND id_reg = :id_reg". $prix_req .") as count_pro, (SELECT COUNT(une) FROM ". PREFIX ."annonces_search WHERE etat = :etat AND une = :une AND id_reg = :id_reg". $prix_req .") as count_une"; $req = $bdd->prepare($sql); $req->bindValue('etat', 2, PDO::PARAM_INT); $req->bindValue('status_par', 1, PDO::PARAM_INT); $req->bindValue('status_pro', 2, PDO::PARAM_INT); $req->bindValue('une', 1, PDO::PARAM_INT); $req->bindValue('id_reg', $id, PDO::PARAM_INT); if($tri == 2) $req->bindValue('prix', 0, PDO::PARAM_INT); $req->execute(); $result = result_to_array($req); return $result; } /////////////////// //Obtenir les annonces et les annonces à la une de la page de recherche par région /////////////////// function get_annonces_reg($id, $f, $offset, $limit, $tri, $une) { global $conn; $bdd = $conn; $f = (int) $f; $tri = (int) $tri; $une = (int) $une; $status_req = ($f == 1 || $f == 2) ? " AND s.status = :status" : ""; $prix_req = ($tri == 2) ? " AND s.prix > :prix" : ""; $une_req = ($une == 1) ? " AND s.une = :une" : ""; $order_req = ($tri == 2) ? " ORDER BY s.prix ASC" : " ORDER BY s.date DESC"; $sql = "SELECT s.id_ann, s.id_reg, s.id_dep, s.id_cat, s.code_pos, s.status, s.type, s.titre, s.ann, s.prix, s.date, s.urg, o.enc, a.ville, a.n_photo, i.nom AS nom_image, v.video FROM ". PREFIX ."annonces_search s LEFT JOIN ". PREFIX ."annonces a ON s.id_ann = a.id_ann LEFT JOIN ". PREFIX ."annonces_images i ON s.id_ann = i.id_ann AND i.id_ima = (SELECT MIN(id_ima) FROM ". PREFIX ."annonces_images WHERE id_ann = s.id_ann) LEFT JOIN ". PREFIX ."annonces_options o ON s.id_ann = o.id_ann LEFT JOIN ". PREFIX ."annonces_video v ON s.id_ann = v.id_ann WHERE s.etat = :etat AND s.id_reg = :id_reg ". $status_req . $prix_req . $une_req . $order_req ." LIMIT :offset, :limit"; $req = $bdd->prepare($sql); $req->bindValue('etat', 2, PDO::PARAM_INT); $req->bindValue('id_reg', $id, PDO::PARAM_INT); if($f == 1 || $f == 2) $req->bindValue('status', $f, PDO::PARAM_INT); if($tri == 2) $req->bindValue('prix', 0, PDO::PARAM_INT); if($une == 1) $req->bindValue('une', 1, PDO::PARAM_INT); $req->bindValue('offset', $offset, PDO::PARAM_INT); $req->bindValue('limit', $limit, PDO::PARAM_INT); $req->execute(); $result = result_to_array($req); return $result; } /////////////////// //Obtenir le nombre d'annonce pro ou particulier en fonction du type /////////////////// function get_nb_annonce_type($type, $tri) { global $conn; $bdd = $conn; $type_req = ($type != 0) ? " AND type = :type" : ""; $prix_req = ($tri == 2) ? " AND prix > :prix" : ""; $sql = "SELECT (SELECT COUNT(status) FROM ". PREFIX ."annonces_search WHERE etat = :etat AND status = :status_par ". $type_req . $prix_req .") as count_par, (SELECT COUNT(status) FROM ". PREFIX ."annonces_search WHERE etat = :etat AND status = :status_pro ". $type_req . $prix_req .") as count_pro, (SELECT COUNT(une) FROM ". PREFIX ."annonces_search WHERE etat = :etat AND une = :une ". $type_req . $prix_req .") as count_une"; $req = $bdd->prepare($sql); $req->bindValue('etat', 2, PDO::PARAM_INT); $req->bindValue('status_par', 1, PDO::PARAM_INT); $req->bindValue('status_pro', 2, PDO::PARAM_INT); $req->bindValue('une', 1, PDO::PARAM_INT); if($type != 0) $req->bindValue('type', $type, PDO::PARAM_INT); if($tri == 2) $req->bindValue('prix', 0, PDO::PARAM_INT); $req->execute(); $result = result_to_array($req); return $result; } /////////////////// //Obtenir les annonces et les annonces à la une de la recherche par type /////////////////// function get_annonces_type($type, $f, $offset, $limit, $tri, $une) { global $conn; $bdd = $conn; $type = (int) $type; $tri = (int) $tri; $une = (int) $une; $type_req = ($type != 0) ? " AND s.type = :type" : ""; $status_req = ($f == 1 || $f == 2) ? " AND s.status = :status" : ""; $prix_req = ($tri == 2) ? " AND s.prix > :prix" : ""; $une_req = ($une == 1) ? " AND s.une = :une" : ""; $order_req = ($tri == 2) ? " ORDER BY s.prix ASC" : " ORDER BY s.date DESC"; $sql = "SELECT s.id_ann, s.id_reg, s.id_dep, s.id_cat, s.code_pos, s.status, s.type, s.titre, s.ann, s.prix, s.date, s.urg, o.enc, a.ville, a.n_photo, i.nom AS nom_image, v.video FROM ". PREFIX ."annonces_search s LEFT JOIN ". PREFIX ."annonces a ON s.id_ann = a.id_ann LEFT JOIN ". PREFIX ."annonces_images i ON s.id_ann = i.id_ann AND i.id_ima = (SELECT MIN(id_ima) FROM ". PREFIX ."annonces_images WHERE id_ann = s.id_ann) LEFT JOIN ". PREFIX ."annonces_options o ON s.id_ann = o.id_ann LEFT JOIN ". PREFIX ."annonces_video v ON s.id_ann = v.id_ann WHERE s.etat = :etat ". $type_req . $status_req . $prix_req . $une_req . $order_req ." LIMIT :offset, :limit"; $req = $bdd->prepare($sql); $req->bindValue('etat', 2, PDO::PARAM_INT); if($type != 0) $req->bindValue('type', $type, PDO::PARAM_INT); if($f == 1 || $f == 2) $req->bindValue('status', $f, PDO::PARAM_INT); if($tri == 2) $req->bindValue('prix', 0, PDO::PARAM_INT); if($une == 1) $req->bindValue('une', 1, PDO::PARAM_INT); $req->bindValue('offset', $offset, PDO::PARAM_INT); $req->bindValue('limit', $limit, PDO::PARAM_INT); $req->execute(); $result = result_to_array($req); return $result; } /////////////////// //Obtenir le résulat de la recherche /////////////////// function make_sql($array, $array_keywords) { global $conn, $language, $cache_search_valeurs; $bdd = $conn; $code_pos = (!empty($array['zip_code']) AND $array['zip_code'] != $language['value_code_postal']) ? $bdd->quote($array['zip_code']) : 0; $reg = (!empty($array['reg'])) ? (int) $array['reg'] : 0; $dep = (!empty($array['dep'])) ? (int) $array['dep'] : 0; $cat = (!empty($array['cat'])) ? htmlspecialchars($array['cat']) : 0; $cat_sql = (!empty($array['cat'])) ? (int) $array['cat'] : 0; $condition = " s.etat = 2"; $condition .= (!empty($reg)) ? " AND s.id_reg = $reg" : ""; $condition .= (!empty($dep)) ? " AND s.id_dep = $dep" : ""; if(!empty($cat) && !is_numeric($cat)) { $select_id_cat = "SELECT id_cat FROM ". PREFIX ."categories WHERE par_cat = (SELECT MIN(id_cat) FROM ". PREFIX ."categories WHERE par_cat = :par_cat AND nom_cat = :nom_cat)"; $req = $bdd->prepare($select_id_cat); $req->bindValue('par_cat', 0, PDO::PARAM_INT); $req->bindValue('nom_cat', $cat, PDO::PARAM_STR); $req->execute(); $result = $req->fetchAll(); $req->closeCursor(); $i = 0; if(!empty($result)) { $condition .= " AND ("; foreach($result as $id_cat) { if($i == 0) $condition .= "s.id_cat = ". (int) $id_cat[0] .""; else $condition .= " OR s.id_cat = ". (int) $id_cat[0] .""; $i++; } $condition .= ")"; } else $condition .= " AND s.id_cat = $cat_sql"; } elseif($cat != 0) $condition .= " AND s.id_cat = $cat_sql"; $condition .= (!empty($code_pos)) ? " AND s.code_pos = $code_pos" : ""; //Les annonces offres uniquement if(!empty($array['offres'])) $condition .= " AND s.type IN (1"; //Les annonces recherches uniquement if(!empty($array['recherches']) && !empty($array['offres'])) $condition .= ", 2"; elseif(!empty($array['recherches'])) $condition .= " AND s.type IN (2"; //Les annonces echanges uniquement if(!empty($array['echanges']) && (!empty($array['offres']) || !empty($array['recherches']))) $condition .= ", 3"; elseif(!empty($array['echanges'])) $condition .= " AND s.type IN (3"; //Les annonces dons uniquement if(!empty($array['dons']) && (!empty($array['offres']) || !empty($array['recherches']) || !empty($array['echanges']))) $condition .= ", 4"; elseif(!empty($array['dons'])) $condition .= " AND s.type IN (4"; //Fermeture de la condition if(!empty($array['offres']) || !empty($array['recherches']) || !empty($array['echanges']) || !empty($array['dons'])) $condition .= ")"; //Condition avec mots clé if(file_exists('includes/engine/search_a_optimized.php')) { require_once('includes/engine/search_a_optimized.php'); } else { if(!empty($array['titre']) && is_array($array_keywords)) { $num = count($array_keywords); $condition .= " AND CONCAT_WS(' ', s.titre) REGEXP '[[:<:]]$array_keywords[0][[:>:]]'"; if($num != 1) { for($i = 1; $i < $num; $i++) { if(empty($array_keywords[$i])) $condition .= ""; else $condition .= " AND CONCAT_WS(' ', s.titre) REGEXP '[[:<:]]$array_keywords[$i][[:>:]]'"; } } } elseif(is_array($array_keywords)) { $num = count($array_keywords); $condition .= " AND CONCAT_WS(' ', s.titre, s.ann) REGEXP '[[:<:]]$array_keywords[0][[:>:]]'"; if($num != 1) { for($i = 1; $i < $num; $i++) { if(empty($array_keywords[$i])) $condition .= ""; else $condition .= " AND CONCAT_WS(' ', s.titre, s.ann) REGEXP '[[:<:]]$array_keywords[$i][[:>:]]' "; } } } } // Recherche avec l'option par prix foreach($cache_search_valeurs as $v) { $id_cat = (int) $v['id_cat']; $sel_nom = htmlspecialchars($v['sel_nom']); $id_opt = (int) $v['id_opt']; if($id_cat == $cat && preg_match("#max$#", $sel_nom) == false) { $sel1 = (isset($array['sel'. $id_opt .'_1'])) ? (int) $array['sel'. $id_opt .'_1'] : 0; $sel2 = (isset($array['sel'. $id_opt .'_2'])) ? (int) $array['sel'. $id_opt .'_2'] : 0; $_SESSION['search']['sel'. $id_opt .'_1'] = $sel1; $_SESSION['search']['sel'. $id_opt .'_2'] = $sel2; if($id_opt == 0) { if($sel1 != 0 && $sel2 != 0) $condition .=" AND s.prix BETWEEN $sel1 AND $sel2"; elseif($sel1 == 0 && $sel2 != 0) $condition .=" AND s.prix <= $sel2"; elseif($sel1 != 0 && $sel2 == 0) $condition .=" AND s.prix >= $sel1"; } } } //Requête $sql = "SELECT s.id_ann, s.id_reg, s.id_dep, s.id_cat, s.code_pos, s.status, s.type, s.titre, s.ann, s.prix, s.date, s.urg, o.enc, a.ville, a.n_photo, i.nom AS nom_image, v.video FROM ". PREFIX ."annonces_search s LEFT JOIN ". PREFIX ."annonces a ON s.id_ann = a.id_ann LEFT JOIN ". PREFIX ."annonces_images i ON s.id_ann = i.id_ann AND i.id_ima = (SELECT MIN(id_ima) FROM ". PREFIX ."annonces_images WHERE id_ann = a.id_ann) LEFT JOIN ". PREFIX ."annonces_options o ON s.id_ann = o.id_ann LEFT JOIN ". PREFIX ."annonces_video v ON s.id_ann = v.id_ann WHERE ". $condition; $sql_count = "SELECT (SELECT COUNT(s.status) FROM ". PREFIX ."annonces_search s LEFT JOIN ". PREFIX ."annonces a ON s.id_ann = a.id_ann WHERE ". $condition ." AND s.status = 1 req_count) as count_par, (SELECT COUNT(s.status) FROM ". PREFIX ."annonces_search s LEFT JOIN ". PREFIX ."annonces a ON s.id_ann = a.id_ann WHERE ". $condition ." AND s.status = 2 req_count) as count_pro, (SELECT COUNT(s.une) FROM ". PREFIX ."annonces_search s LEFT JOIN ". PREFIX ."annonces a ON s.id_ann = a.id_ann WHERE ". $condition ." AND s.une= 1 req_count) as count_une"; $result = array('sql' => $sql, 'sql_count' => $sql_count); return $result; } /////////////////// //Obtenir le résulat des options de la recherche /////////////////// function make_options($array) { global $conn, $cache_search_valeurs, $cache_search_donnees, $cache_search_checkbox, $cache_select_checkbox; $bdd = $conn; $cat = (!empty($array['cat'])) ? (int) $array['cat'] : 0; $options = ''; //Annonces urgentes et/ou avec photo $options .= (!empty($array['urgentes'])) ? " AND s.urg = 1" : ""; $options .= (!empty($array['photo'])) ? " AND s.photo = 1" : ""; $options .= (!empty($array['video'])) ? " AND s.video = 1" : ""; // Recherche avec options de valeurs foreach($cache_search_valeurs as $v) { $id_cat = (int) $v['id_cat']; $sel_nom = htmlspecialchars($v['sel_nom']); $id_opt = (int) $v['id_opt']; if($id_cat == $cat && preg_match("#max$#", $sel_nom) == false) { $sel1 = (isset($array['sel'. $id_opt .'_1'])) ? (int) $array['sel'. $id_opt .'_1'] : 0; $sel2 = (isset($array['sel'. $id_opt .'_2'])) ? (int) $array['sel'. $id_opt .'_2'] : 0; $_SESSION['search']['sel'. $id_opt .'_1'] = $sel1; $_SESSION['search']['sel'. $id_opt .'_2'] = $sel2; if($id_opt != 0) { if($sel1 != 0 && $sel2 != 0) $options .=" AND (SELECT val_for FROM ". PREFIX ."annonces_valeurs WHERE id_opt = $id_opt AND id_ann = s.id_ann) BETWEEN $sel1 AND $sel2"; elseif($sel1 == 0 && $sel2 != 0) $options .=" AND (SELECT val_for FROM ". PREFIX ."annonces_valeurs WHERE id_opt = $id_opt AND id_ann = s.id_ann) <= $sel2"; elseif($sel1 != 0 && $sel2 == 0) $options .=" AND (SELECT val_for FROM ". PREFIX ."annonces_valeurs WHERE id_opt = $id_opt AND id_ann = s.id_ann) >= $sel1"; } } } // Recherche avec options de données $num = 1; foreach($cache_search_donnees as $v) { $num = ($num%2) ? 1 : 2; $id_cat = (int) $v['id_cat']; $id_opt = (int) $v['id_opt']; if($id_cat == $cat) { if(isset($array['sel'. $id_opt .'_'. $num])) { $sel = $array['sel'. $id_opt .'_'. $num]; $sel_sql = $bdd->quote($array['sel'. $id_opt .'_'. $num]); } else $sel = 0; $_SESSION['search']['sel'. $id_opt .'_'. $num] = $sel; if(!empty($sel)) $options .= " AND (SELECT val_for FROM ". PREFIX ."annonces_valeurs WHERE id_opt = $id_opt AND id_ann = s.id_ann) = $sel_sql"; $num++; } } // Recherche avec options checkbox foreach($cache_search_checkbox as $v) { $id_cat = (int) $v['id_cat']; $id_opt = (int) $v['id_opt']; $num = 1; if($id_cat == $cat) { foreach($cache_select_checkbox as $row) { if($v['id_opt'] == $row['id_opt']) { if(isset($array['sel'. $id_opt .'_'. $num])) { $sel = $array['sel'. $id_opt .'_'. $num]; $sel_sql = $bdd->quote($array['sel'. $id_opt .'_'. $num]); } else $sel = 0; $_SESSION['search']['sel'. $id_opt .'_'. $num] = $sel; if(!empty($sel)) $options .= " AND (SELECT val_for FROM ". PREFIX ."annonces_valeurs WHERE id_opt = $id_opt AND val_for = $sel_sql AND id_ann = s.id_ann) = $sel_sql"; $num++; } } } } return $options; } /////////////////// //Obtenir le nombre d'annonce de la page de recherche /////////////////// function get_nb_annonces_search($sql, $options, $tri) { global $conn; $bdd = $conn; $tri = ($tri == 2) ? " AND s.prix > 0" : ""; $sql = str_replace('req_count', $options . $tri, $sql); $req = $bdd->prepare($sql); $req->execute(); $result = result_to_array($req); return $result; } /////////////////// //Obtenir les annonces de la page de recherche /////////////////// function get_annonces_search($sql, $options, $f, $offset, $limit, $tri, $une) { global $conn; $bdd = $conn; $offset = (int) $offset; $limit = (int) $limit; $tri = (int) $tri; $une = (int) $une; $f = (int) $f; $condition = ($tri == 2) ? " AND s.prix > 0" : ""; $condition .= ($f == 1 || $f == 2) ? " AND s.status = $f" : ""; $une = ($une == 1) ? " AND s.une = 1" : ""; $order = ($tri == 2) ? " ORDER BY s.prix ASC" : " ORDER BY s.date DESC"; $sql = $sql . $condition . $une . $options . $order ." LIMIT $offset, $limit"; $req = $bdd->prepare($sql); $req->execute(); $result = result_to_array($req); return $result; }