| 12
 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
 
 | <?php
function sql_connexion() {
	global $mysqli;
	$mysqli = new mysqli("localhost", "", "", "");
 
	/* Vérification de la connexion */
	if(mysqli_connect_errno()) {
		printf("Échec de la connexion : %s\n", mysqli_connect_error());
		exit();
	}
	// $mysqli->query("SET NAMES 'utf8' ");
}
function sql_requete($query) {
	global $mysqli;
	$result = $mysqli->query($query);
	if(!$result) {
		// Erreur dans la requete
		echo '<p>ERROR '. $mysqli->errno .'</strong> >> '. $mysqli->error .'</p>';
		return false;
	} else {
		// Tout va bien
		return $result;
	}
}
if(isset($_GET['q']) && $_GET['q'] != '') {
	$recherche = stripslashes($_GET['q']);
} else {
	$recherche = '';
}
?>
 
<?php
 
if($recherche != '') {
	sql_connexion();
 
	$query  = "SELECT nom, prix,  image120, idneta, rubrique, keywords, nommarchand, id_prod,   descriptif, url ";
	$query .= "FROM catalogue " ;
	$query .= "WHERE nom REGEXP '". addslashes($recherche) ."' ";
	//$query .=    "OR  REGEXP '". addslashes($recherche) ."' ";
 
	if ($result = sql_requete($query)) {
		if($result->num_rows > 0) {
 
 
			 //echo (int)($result->num_rows > 0);
 
    	echo '<table class="sortable" >';
      echo '<th>image</th>';
    	echo '<th>nom</th>';
			echo '<th>description</th>';
			echo '<th>prix</th>';
			echo '<th>marchand</th>';
			echo '<th>lien</th>';
 
			/* Récupère un tableau d'objets */
			while ($obj = $result->fetch_object()) {
 
				echo '<tr onmouseover="this.className=\'hover\';" onmouseout="this.className=\'\';">';
				echo	'<td class="img"><img src="' . htmlspecialchars($obj->image120) . '" alt="" /></td>';
				echo	'<td class="nom">' . htmlspecialchars($obj->nom) . '</td>';
				echo	'<td class="des">'. htmlspecialchars($obj->descriptif) .  ' <br><br><div class="note"><a href="avis.php?id_prod='.$obj->id_prod.'">Avis sur le produit</a></div></td>';
				echo	'<td class="pri">   ' . htmlspecialchars($obj->prix) . '  </td>';
				echo	'<td class="img"> <img src="'.($obj->nommarchand) .'"> </td>';
					echo	'<td class="lien"><a href="details.php?id_prod=' . htmlspecialchars($obj->id_prod) . ' "target="blank">Voir le produit</a></td>';
 
        echo '</tr>';
 
			}	
			echo '</table>';
 
			/* free result set */
			$result->close();
		} else {
		echo "<td class='essai'>Votre recherche n'a retourné aucun résultat.</td>"; 
		}
	}
	/* Fermeture de la connexion */
	$mysqli->close();
}
?> | 
Partager