le 14/05/2009 à 08:59
PHP MySQL : récupération de paramètres afin de générer une requete SQL
si, mais je ne vois pas la requête s'afficher, il n'y a que la liste de tout les enregistrements de la BDD qui s'affiche
<?php
session_start();
?>
<?php
global $num_uc, $garantie_uc, $marque_uc, $date_ach_uc, $type_uc, $date_affect_uc, $num_inv_uc, $num_serie_uc, $materiel, $nom_util, $service, $unite, $marque_ecran, $garantie_ecran, $type_ecran, $date_ach_ecran, $num_inv_ecran, $date_affect_ecran, $num_serie_ecran, $cpu, $cad_cpu, $ram, $dram, $dd, $se, $lecteur, $dao, $adr_ip, $dns, $masque, $wins, $passerelle, $date_d, $date_f;
?>
<HTML>
<HEAD>
<LINK REL="stylesheet" HREF="../styles/dde53.css" TYPE="text/css">
<?php
include ('div.php');
?>
</HEAD>
<BODY>
<?php
include ('date.php');
include ('connect.php');
$idconnect = bddconnect();
if ($idconnect) {
$ok = false;
$ip = false;
$name = $nom_util;
if ($num_uc != "") { $num_uc = "AND micro.num_uc LIKE '%".$num_uc."%' "; $ok = true; }
if ($garantie_uc != "") { $garantie_uc = "AND uc.garantie_uc LIKE '".$garantie_uc."' "; $ok = true; }
if ($marque_uc != "") { $marque_uc = "AND uc.marque_uc LIKE '".$marque_uc."' "; $ok = true; }
if ($date_ach_uc != "") { $date_ach_uc = "AND uc.date_ach_uc LIKE '".$date_ach_uc."' "; $ok = true; }
if ($type_uc != "") { $type_uc = "AND uc.type_uc LIKE '".$type_uc."' "; $ok = true; }
if ($date_affect_uc != "") { $date_affect_uc = "AND uc.date_affect_uc LIKE '".$date_affect_uc."' "; $ok = true; }
if ($num_inv_uc != "") { $num_inv_uc = "AND uc.num_inv_uc LIKE '".$num_inv_uc."' "; $ok = true; }
if ($num_serie_uc != "") { $num_serie_uc = "AND uc.num_serie_uc LIKE '".$num_serie_uc."' "; $ok = true; }
if ($materiel != "") { $materiel = "AND micro.materiel LIKE '".$materiel."' "; $ok = true; }
if ($nom_util != "") { $nom_user = "AND micro.nom_util LIKE '%".$nom_util."%'"; $ok = true; }
if ($service != "") { $service = "AND micro.service LIKE '".$service."' "; $ok = true; }
if ($unite != "") { $unite = "AND micro.unite LIKE '".$unite."' "; $ok = true; }
if ($marque_ecran != "") { $marque_ecran = "AND ecran.marque_ecran LIKE '".$marque_ecran."' "; $ok = true; $ecr = true; }
if ($garantie_ecran != "") { $garantie_ecran = "AND ecran.garantie_ecran LIKE '".$garantie_ecran."' "; $ok = true; $ecr = true; }
if ($type_ecran != "") { $type_ecran = "AND ecran.type_ecran = '".$type_ecran."' "; $ok = true; $ecr = true; }
if ($date_ach_ecran != "") { $date_ach_ecran = "AND ecran.date_ach_ecran LIKE '".$date_ach_ecran."' "; $ok = true; $ecr = true; }
if ($num_inv_ecran != "") { $num_inv_ecran = "AND ecran.num_inv_ecran LIKE '".$num_inv_ecran."' "; $ok = true; $ecr = true; }
if ($date_affect_ecran != "") { $date_affect_ecran = "AND ecran.date_affect_ecran LIKE '".$date_affect_ecran."' "; $ok = true; $ecr = true; }
if ($num_serie_ecran != "") { $num_serie_ecran = "AND ecran.num_serie_ecran LIKE '".$num_serie_ecran."' "; $ok = true; $ecr = true; }
if ($cpu != "") { $cpu = "AND uc.cpu LIKE '".$cpu."' "; $ok = true; }
if ($cad_cpu != "") { $cad_cpu = "AND uc.cad_cpu LIKE '".$cad_cpu."' "; $ok = true; }
if ($ram != "") { $ram = "AND uc.ram LIKE '".$ram."' "; $ok = true; }
if ($dram != "") { $dram = "AND uc.dram_uc LIKE '".$dram."' "; $ok = true; }
if ($dd != "") { $dd = "AND uc.dd LIKE '".$dd."' "; $ok = true; }
if ($se != "") { $se = "AND uc.se LIKE '".$se."' "; $ok = true; }
if ($lecteur != "") { $lecteur = "AND uc.lecteur LIKE '".$lecteur."' "; $ok = true; }
if ($dao != "") { $dao = "AND uc.dao LIKE '".$dao."' "; $ok = true; }
if ($adr_ip != "") { $adr_ip = "AND ip.ip LIKE '".$adr_ip."' "; $ok = true; $ip=true; }
if ($dns != "") { $dns = "AND ip.dns LIKE '".$dns."' "; $ok = true; $ip=true; }
if ($masque != "") { $masque = "AND ip.masque LIKE '".$masque."' "; $ok = true; $ip=true; }
if ($wins != "") { $wins = "AND ip.wins LIKE '".$wins."' "; $ok = true; $ip=true; }
if ($passerelle != "") { $passerelle = "AND ip.passerelle LIKE '".$passerelle."' "; $ok = true; $ip=true; }
if ($date_d = "") { $date_d = "%"; }
if ($date_f = "") { $date_f = "%"; }
if ($ok == true ) { // Si au moins un des critères a été renseigné
$req = "SELECT * FROM micro, uc "; // Création de la requête avec les table micro, uc et ecran
if ($ip == true) { // Ajout de la table IP dans la requête
$req .= ", ip ";
}
if ($ecr == true) {
$req .= ", ecran ";
}
$req .= "WHERE micro.ref_uc = uc.ref_uc "; // Jointures
if ($ip == true) { // Ajout des champs IP, DNS, PSRL, DNS et WINS de la table IP dans la requête + joiture avec la table IP
$req .= "AND micro.ref_ip = ip.ref_ip ";
$req .= $adr_ip." ";
$req .= $masque." ";
$req .= $passerelle." ";
$req .= $dns." ";
$req .= $wins." ";
}
if ($ecr == true) {
$req .= "AND micro.ref_ecran = ecran.ref_ecran ";
$req .= $marque_ecran." ";
$req .= $type_ecran." ";
$req .= $garantie_ecran." ";
$req .= $num_inv_ecran." ";
$req .= $num_serie_ecran." ";
$req .= $date_ach_ecran." ";
$req .= $date_affect_ecran." ";
}
$req .= $num_uc." ";
$req .= $nom_user." ";
$req .= $service." ";
$req .= $unite." ";
$req .= $materiel." ";
$req .= $marque_uc." ";
$req .= $type_uc." ";
$req .= $num_inv_uc." ";
$req .= $num_serie_uc." ";
$req .= $date_ach_uc." ";
$req .= $date_affect_uc." ";
$req .= $garantie_uc." ";
$req .= $cpu." ";
$req .= $cad_cpu." ";
$req .= $dd." ";
$req .= $ram." ";
$req .= $dram." ";
$req .= $lecteur." ";
$req .= $se." ";
$req .= $dao." ";
$req .= "ORDER BY micro.num_uc";
} else { // Sinon, sélection de l'ensemble des micros
$req = "SELECT * FROM micro, uc WHERE micro.ref_uc = uc.ref_uc ORDER BY num_uc";
}
$res = mysql_query($req);
$num = mysql_num_rows($res);
if ($res) {
if ($num == 0) {
echo 'Aucune fiche trouvée !!<p>';
echo '<a href="form_search_fiche.php?p=m">Retour</a>';
} else
{
echo '<form name="selection" action="caract_micro.php" method="POST">';
echo '<table width="100%">';
echo '<tr><td width="100%" class="fondblanc_txtbleu14g" align="center">Résultat de la recherche</td></tr>';
if ($num == 1) {
echo '<tr><td width="100%" class="fondblanc_txtbleu14g" align="center">'.$num.' fiche trouvée</td></tr>';
} else {
echo '<tr><td width="100%" class="fondblanc_txtbleu14g" align="center">'.$num.' fiches trouvées</td></tr>';
}
echo '<tr><td height="10"></td></tr>';
echo '<tr><td width="100%">';
echo '<table width="98%" border=0 cellspacing=0>';
echo '<tr class="fondjaunepale_txtbleu12g">';
echo '<td width="5%">Choix</td>';
echo '<td width="10%" align="center">N° du micro</td>';
echo '<td width="20%" align="center">Marque</td>';
echo '<td width="20%" align="center">Type</td>';
echo '<td width="20%" align="center">Utilisateur</td>';
echo '<td width="12%" align="center">Service</td>';
echo '<td width="15%" align="center">Unité</td></tr>';
echo '</table>';
echo '</td></tr><tr><td>';
?>
<div class="tab">
<?
echo '<table width="100%" border=1 cellspacing=0>';
$_SESSION['tab_micro'] = array();
$i=0;
while ($ligne = mysql_fetch_array ($res))
{
$ref = $ligne[0];
$num_m = $ligne[1];
$marque = $ligne[16];
$type = $ligne[17];
$nom = $ligne[4];
$service = $ligne [2];
$unite = $ligne[3];
$_SESSION['tab_micro'][$i] = $ref;
//Selection du libellé long pour la marque
if ($marque != "") {
$req4="SELECT * FROM marque WHERE lbl_court_marque = '".$marque."'";
$res4=mysql_query($req4);
while ($ligne = mysql_fetch_array ($res4)) { $marque = $ligne[2]; }
} else {
$marque = " ";
}
//Selection du libellé long pour le type
if ($type != "") {
$req5="SELECT * FROM type_uc WHERE lbl_court_type = '".$type."'";
$res5=mysql_query($req5);
while ($ligne = mysql_fetch_array ($res5)) { $type = $ligne[2]; }
} else {
$type = " ";
}
//Affichage de la ligne correspondant à un micro
echo '<tr class="fondblanc_txtbleu12">';
echo '<td align="center" width="5%"><input type="radio" name="select" value="'.$ref.'"></td>';
echo '<td width="10%">'.$num_m.'</td>';
echo '<td width="20%">'.$marque.'</td>';
echo '<td width="20%">'.$type.'</td>';
echo '<td width="20%">'.$nom.'</td>';
echo '<td width="12%">'.$service.'</td>';
echo '<td width="15%">'.$unite.'</td></tr>';
$i++;
}
echo '</table>';
echo '</td></tr>';
echo '<tr><td height="5"></td></tr>';
echo '<tr><td align="center"><input type="submit" value=" Voir ">    ';
echo '<input type="button" value=" Retour " onclick="javascript:parent.frames[\'body\'].window.location=\'body.php\';">';
if ($_SESSION['grade'] == 'administrateur')
{
echo '    <input type="button" value="Actions" onclick="parent.frames[\'body\'].window.location=\'form_select_action.php\'"></td></tr>';
}
echo '<tr><td align="center"><input type="button" value="Nouvelle recherche" onclick="javascript:history.go(-1);"></td></tr>';
echo '<tr><td align="center"><a href="print_search.php?req='.$req.'" target="_blank">Imprimer</a></td></tr>';
echo '</table>';
echo '</form>';
}
} else {
echo 'ERREUR<p>';
echo '<a href="body.php" traget="body">Retour</a>';
}
}
?>
</body>
</html>
Chargement en cours