Files

241 lines
4.6 KiB
PHP
Executable File

<?php
session_start();
$marq=$HTTP_POST_VARS["marq"];
$rech=$HTTP_POST_VARS["rech"];
if (!$marq)
{
$marq=$HTTP_GET_VARS["marq"];
}
if (!$rech)
{
$rech=$HTTP_GET_VARS["rech"];
}
?>
<html>
<head>
<title>
Recherche produit
</title>
<link href="../style.css" rel="stylesheet" type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><style type="text/css">
<!--
a:link {
color: #FFFFFF;
text-decoration: none;
}
a:visited {
text-decoration: none;
color: #FFFFFF;
}
a:hover {
text-decoration: underline;
color: #FFFFFF;
}
a:active {
text-decoration: none;
color: #FFFFFF;
}
.style1 {
font-size: xx-small;
font-style: italic;
}
-->
</style></head>
<body class="bgcolor" text="white">
<?php
require("../connexion.php");
$conn = mysql_connect($host, $user, $password);
mysql_select_db($bdd) or die("Impossible d'ouvrir la base de donnee $bdd");
?>
<div align=center>
<table border=0>
<tr align=center>
<td width="91">
</td>
<td width="91">
</td>
<td width="39">
</td>
<td width="17">
</td>
<td width="28">
</td>
<td width="28">
</td>
</tr>
<tr>
<td colspan=6>
&nbsp
</td>
<tr>
<?php
// CAS RECHERCHE MARQUE
if ($marq)
{
$query = " select distinct count(idprod) from produit where idmarque='$marq'";
$resultq=mysql_query($query) or die ("Erreur SQL :$query<br>".mysql_error()."...");
while ($ligne=mysql_fetch_row($resultq))
{
$nbprod=$ligne[0];
}
print "il y a $nbprod resultat<br>&nbsp";
$requete = "select idprod,denomination,description,refconst from produit where idmarque='$marq'";
$result=mysql_query($requete) or die ("Erreur SQL :$requete<br>".mysql_error()."...");
while ($ligne=mysql_fetch_row($result))
{
$idprod=$ligne[0];
$nom=$ligne[1];
$desc=$ligne[2];
$ref=$ligne[3];
?>
<tr>
<td>
<a href="detailprod.php?idprod=<?php print $idprod?>&marq=<?php print $marq?>"><?php print $nom?></a></td>
<td><span class="style1">
<h6>| <?php print $desc?></h6>
</span></td>
<td>
| <?php print $ref?>
</td>
</tr>
<?php
}
}
?>
<?php
// CAS RECHERCHE TEXTE
if ($rech)
{
$query = "
select distinct count(idprod)
from produit p,categorie c,famille f,marques m
where
p.idmarque=m.idmarque AND p.idfamille=f.idfamille AND f.idcateg=c.idcateg
AND ((lower(denomination) LIKE lower('%$rech%')) OR (lower(description) LIKE lower('%$rech%')) OR (lower(refconst) LIKE lower('%$rech%')) OR (lower(marque) LIKE lower('%$rech%')) OR (lower(nomcateg) LIKE lower('%$rech%')) OR (lower(nomfamille) LIKE lower('%$rech%'))) ";
$resultq=mysql_query($query) or die ("Erreur SQL :$query<br>".mysql_error()."...");
while ($ligne=mysql_fetch_row($resultq))
{
$nbprod=$ligne[0];
}
print "il y a $nbprod resultats<br>&nbsp";
$requete= "
select distinct idprod,denomination,description,refconst,m.idmarque,marque,p.idfamille,f.nomfamille,f.idcateg,c.nomcateg
from produit p,categorie c,famille f,marques m
where
p.idmarque=m.idmarque AND p.idfamille=f.idfamille AND f.idcateg=c.idcateg
AND ((lower(denomination) LIKE lower('%$rech%')) OR (lower(description) LIKE lower('%$rech%')) OR (lower(refconst) LIKE lower('%$rech%')) OR (lower(marque) LIKE lower('%$rech%')) OR (lower(nomcateg) LIKE lower('%$rech%')) OR (lower(nomfamille) LIKE lower('%$rech%')))
Order by nomcateg,nomfamille";
$result=mysql_query($requete) or die ("Erreur SQL :$requete<br>".mysql_error()."...");
$cat="";
$fam="";
while ($ligne=mysql_fetch_row($result))
{
$idprod=$ligne[0];
$nom=$ligne[1];
$desc=$ligne[2];
$ref=$ligne[3];
$idmarque=$ligne[4];
$marque=$ligne[5];
$idfamille=$ligne[6];
$famille=$ligne[7];
$idcateg=$ligne[8];
$categorie=$ligne[9];
?>
<tr>
<?php
if ($categorie != $cat)
{
$cat = $categorie;
?>
<tr>
<td>
<b> <?php print $categorie?></b>
</td>
<td colspan=5>
</td>
<tr>
<?php
}
?>
<?php
if ($famille != $fam)
{
$fam = $famille;
?>
<tr>
<td>
</td>
<td>
<?php print $famille?>
</td>
<td colspan=4>
</td>
<tr>
<?php
}
?>
<td>
&nbsp
</td>
<td>
&nbsp
</td>
<td>
<a href="detailprod.php?idprod=<?php print $idprod?>&rech=<?php print $rech?>"><?php print $nom?></a>
</td>
<td>
<?php print $desc?>
</td>
<td>
<?php print $ref?>
</td>
<td>
<?php print $marque?>
</td>
</tr>
<?php
$test="";
//} //fin if
}
}
?>
</table>
</div>
</body>
</html>