par
Cyrano » 28 juil. 2007, 16:43
Que tu ne t'y retrouves pas ne me surprend pas trop : désolé, mais tu codes comme un cochon, c'est illisible. Voici un corrigé un peu remis en forme.
Discipline toi à prendre le temps d'écrire proprement ton code avec une indentation, tu gagneras pas mal de temps en débuggage.
Ce que tu n'as pas remarqué dans l'exemple que j'ai donné plus tôt, c'est que chaque ligne a un div avec un identifiant qui lui est propre, même chose pour le tableau. J'ai donc réutilisé ta variable $i pour ajuster ces identifiants dynamiques et j'ai simplifié ton système d'alternance de couleur de fond de ligne.
Résultat sommaire :
<?php
include("header.php");
include("menumod.php");
?>
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="content-type" />
<title>Rechercher</title>
<link rel="stylesheet" type="text/css" href="css/transparent.css" />
<style type="text/css">
body {
background:;
font-family:Verdana, Arial, Helvetica, sans-serif;
color:black;
font-weight:bold;
font-size: 11px;
}
a:hover {color:white;}
a {text-decoration:none; color:black;}
.Style1 {font-size: x-small}
</style>
<script type="text/javascript">
/* <![CDATA[ */
function $(elt)
{
return document.getElementById(elt);
}
function affichermasquer(idbloc)
{
var etat = $(idbloc).style.display;
$(idbloc).style.display = (etat == 'none') ? 'block' : 'none';
}
/* ]]> */
</script>
<style type="text/css">
/* <![CDATA[ */
div.blocinfo {
position: relative;
}
div.blocinfo p {
z-index: 10;
}
div.blocinfo table {
position: absolute;
top: 25px;
left: 0px;
border: 1px solid #ccc;
z-index: 20;
color: #000;
background-color: #efefef;
border-collapse: collapse;
}
div.blocinfo table td {
border: 1px solid #ccc;
}
/* ]]> */
</style>
</head>
<body>
<span class="Style2">
<form action="rechercho.php" method="post" name="f" enctype="multipart/form-data">
<td><input name="choix" value="nom" checked="checked" type="radio" />nom</td>
<td><input name="choix" value="Adresse" type="radio" />Adresse</td>
<td><input name="choix" value="CP" type="radio" />CP</td>
<td><input name="choix" value="VILLE" type="radio" />Ville</td>
<td> <input type=hidden name=count value="0" size=1 onkeydown="alert('Cette valeur est cre automatiquement!'); return false;">
<td><input type="text" name="recherche" size="30" maxlength="30" /></td>
<input type=hidden name=reset value="Restaurer">
<input name="Rechercher" type="submit" class="button" value="Rechercher" />
</td>
</form>
<div id="rechercheinfo" style="position:absolute; left:350px; top:25px; visibility: hidden">
<table border=1 cellspacing=0 cellpadding=4>
<tr>
<td bgcolor=#FF9900>
<font size=2 face="arial,helvetica" color=#000000><b>
</b></font>
</td>
</tr>
</table>
</div>
<script language="JavaScript">
<!--
document.f.recherche.onkeydown = function()
{
document.f.count.value++;
}
document.f.reset.onclick = function()
{
return(confirm('Voulez-vous vraiment\n'+'annuler toutes les saisies ?'));
}
if(navigator.appName.indexOf('Netscape') != -1)
{
with (document)
{
f.count.onmouseover = function()
{ countinfo.visibility='visible'; }
f.count.onmouseout = function()
{ countinfo.visibility='hidden'; }
f.recherche.onmouseover = function()
{ rechercheinfo.visibility='visible'; }
f.recherche.onmouseout = function()
{ rechercheinfo.visibility='hidden'; }
f.reset.onmouseover = function()
{ resetinfo.visibility='visible'; }
f.reset.onmouseout = function()
{ resetinfo.visibility='hidden'; }
}
}
if(navigator.appName.indexOf('Explorer') != -1)
{
with (document)
{
f.count.onmouseover = function()
{ countinfo.style.visibility='visible'; }
f.count.onmouseout = function()
{ countinfo.style.visibility='hidden'; }
f.recherche.onmouseover = function()
{ rechercheinfo.style.visibility='visible'; }
f.recherche.onmouseout = function()
{ rechercheinfo.style.visibility='hidden'; }
f.reset.onmouseover = function()
{ resetinfo.style.visibility='visible'; }
f.reset.onmouseout = function()
{ resetinfo.style.visibility='hidden'; }
}
}
//-->
</script>
<?php
if ( !$_POST[choix] || !$_POST[recherche])
{
echo "<table width=100% border=1 align=center>";
echo '<tr><td align="center" bgcolor="#cccccc">RECHERCHE :<img src="images/o.png" width="20" height="20"></td></tr>';
echo "</table>";
exit;
}
$connect = mysql_connect("localhost", "root", "") or die ("Echec de la connexion au serveur !");
$select = mysql_select_db("carnet");
$query = "SELECT nom,Adresse,CP,VILLE,coordonnees FROM ident ". $_POST[choix]." LIKE '%".$_POST[recherche]."' ORDER BY nom DESC";
$result = mysql_query($query);
$totenreg = mysql_num_rows($result);
?>
<table width="70%" border="0" align="center" summary="">
<?php
if ( $result && mysql_num_rows($result) ==0)
{
?>
<tr>
<td align="center" bgcolor="#FFFFFF"><center>PAS DE REPONSES CORRESPONDANTES</center></td>
</tr>
<?php
}
elseif ($result)
{
?>
<tr bgcolor="#CCCCCC">
<td colspan="2"><img src="images/o.png" width="20" height="20">NOMBRE DE REPONSES : <?php echo($totenreg); ?></td>
</tr>
<tr align="center" bgcolor="#FFFFCC">
<td align="center" class="Style2">nom</td>
<td align="center" class="Style2">Adresse Postale</td>
</tr>
<?php
$i = 0;
$bgcolor = ($i % 2 == 0) ? 'CCFFFF' : 'EEEEEE';
while ($row = mysql_fetch_array($result))
{
?>
<tr bgcolor=#<?php echo($bgcolor); ?>>
<td class="Style3"><?php echo $row["nom"]; ?>
<div id="blocinfo<?php echo($i); ?>" class="blocinfo">
<p><a href="./" title="Afficher les coordonnées" onmouseover="affichermasquer('tableinfos<?php echo($i); ?>');" onmouseout="affichermasquer('tableinfos<?php echo($i); ?>');">Détails</a></p>
<table id="tableinfos<?php echo($i); ?>" summary="" style="display: none">
<tr>
<td><?php echo $row["coordonnees"]; ?></td>
</tr>
</table>
</div>
</td>
<td align="center" class="Style2"><?php $row['Adresse']." ". $row['CP']." ". $row['VILLE'] ?></td>
</tr>
<?php
$i++;
}
?>
</table>
<?php
}
?>
</body>
</html>
Teste ça et reviens demander des explications si un point t'échappe.
Que tu ne t'y retrouves pas ne me surprend pas trop : désolé, mais tu codes comme un cochon, c'est illisible. Voici un corrigé un peu remis en forme.
Discipline toi à prendre le temps d'écrire proprement ton code avec une indentation, tu gagneras pas mal de temps en débuggage.
Ce que tu n'as pas remarqué dans l'exemple que j'ai donné plus tôt, c'est que chaque ligne a un div avec un identifiant qui lui est propre, même chose pour le tableau. J'ai donc réutilisé ta variable $i pour ajuster ces identifiants dynamiques et j'ai simplifié ton système d'alternance de couleur de fond de ligne.
Résultat sommaire :
[php]<?php
include("header.php");
include("menumod.php");
?>
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="content-type" />
<title>Rechercher</title>
<link rel="stylesheet" type="text/css" href="css/transparent.css" />
<style type="text/css">
body {
background:;
font-family:Verdana, Arial, Helvetica, sans-serif;
color:black;
font-weight:bold;
font-size: 11px;
}
a:hover {color:white;}
a {text-decoration:none; color:black;}
.Style1 {font-size: x-small}
</style>
<script type="text/javascript">
/* <![CDATA[ */
function $(elt)
{
return document.getElementById(elt);
}
function affichermasquer(idbloc)
{
var etat = $(idbloc).style.display;
$(idbloc).style.display = (etat == 'none') ? 'block' : 'none';
}
/* ]]> */
</script>
<style type="text/css">
/* <![CDATA[ */
div.blocinfo {
position: relative;
}
div.blocinfo p {
z-index: 10;
}
div.blocinfo table {
position: absolute;
top: 25px;
left: 0px;
border: 1px solid #ccc;
z-index: 20;
color: #000;
background-color: #efefef;
border-collapse: collapse;
}
div.blocinfo table td {
border: 1px solid #ccc;
}
/* ]]> */
</style>
</head>
<body>
<span class="Style2">
<form action="rechercho.php" method="post" name="f" enctype="multipart/form-data">
<td><input name="choix" value="nom" checked="checked" type="radio" />nom</td>
<td><input name="choix" value="Adresse" type="radio" />Adresse</td>
<td><input name="choix" value="CP" type="radio" />CP</td>
<td><input name="choix" value="VILLE" type="radio" />Ville</td>
<td> <input type=hidden name=count value="0" size=1 onkeydown="alert('Cette valeur est cre automatiquement!'); return false;">
<td><input type="text" name="recherche" size="30" maxlength="30" /></td>
<input type=hidden name=reset value="Restaurer">
<input name="Rechercher" type="submit" class="button" value="Rechercher" />
</td>
</form>
<div id="rechercheinfo" style="position:absolute; left:350px; top:25px; visibility: hidden">
<table border=1 cellspacing=0 cellpadding=4>
<tr>
<td bgcolor=#FF9900>
<font size=2 face="arial,helvetica" color=#000000><b>
</b></font>
</td>
</tr>
</table>
</div>
<script language="JavaScript">
<!--
document.f.recherche.onkeydown = function()
{
document.f.count.value++;
}
document.f.reset.onclick = function()
{
return(confirm('Voulez-vous vraiment\n'+'annuler toutes les saisies ?'));
}
if(navigator.appName.indexOf('Netscape') != -1)
{
with (document)
{
f.count.onmouseover = function()
{ countinfo.visibility='visible'; }
f.count.onmouseout = function()
{ countinfo.visibility='hidden'; }
f.recherche.onmouseover = function()
{ rechercheinfo.visibility='visible'; }
f.recherche.onmouseout = function()
{ rechercheinfo.visibility='hidden'; }
f.reset.onmouseover = function()
{ resetinfo.visibility='visible'; }
f.reset.onmouseout = function()
{ resetinfo.visibility='hidden'; }
}
}
if(navigator.appName.indexOf('Explorer') != -1)
{
with (document)
{
f.count.onmouseover = function()
{ countinfo.style.visibility='visible'; }
f.count.onmouseout = function()
{ countinfo.style.visibility='hidden'; }
f.recherche.onmouseover = function()
{ rechercheinfo.style.visibility='visible'; }
f.recherche.onmouseout = function()
{ rechercheinfo.style.visibility='hidden'; }
f.reset.onmouseover = function()
{ resetinfo.style.visibility='visible'; }
f.reset.onmouseout = function()
{ resetinfo.style.visibility='hidden'; }
}
}
//-->
</script>
<?php
if ( !$_POST[choix] || !$_POST[recherche])
{
echo "<table width=100% border=1 align=center>";
echo '<tr><td align="center" bgcolor="#cccccc">RECHERCHE :<img src="images/o.png" width="20" height="20"></td></tr>';
echo "</table>";
exit;
}
$connect = mysql_connect("localhost", "root", "") or die ("Echec de la connexion au serveur !");
$select = mysql_select_db("carnet");
$query = "SELECT nom,Adresse,CP,VILLE,coordonnees FROM ident ". $_POST[choix]." LIKE '%".$_POST[recherche]."' ORDER BY nom DESC";
$result = mysql_query($query);
$totenreg = mysql_num_rows($result);
?>
<table width="70%" border="0" align="center" summary="">
<?php
if ( $result && mysql_num_rows($result) ==0)
{
?>
<tr>
<td align="center" bgcolor="#FFFFFF"><center>PAS DE REPONSES CORRESPONDANTES</center></td>
</tr>
<?php
}
elseif ($result)
{
?>
<tr bgcolor="#CCCCCC">
<td colspan="2"><img src="images/o.png" width="20" height="20">NOMBRE DE REPONSES : <?php echo($totenreg); ?></td>
</tr>
<tr align="center" bgcolor="#FFFFCC">
<td align="center" class="Style2">nom</td>
<td align="center" class="Style2">Adresse Postale</td>
</tr>
<?php
$i = 0;
$bgcolor = ($i % 2 == 0) ? 'CCFFFF' : 'EEEEEE';
while ($row = mysql_fetch_array($result))
{
?>
<tr bgcolor=#<?php echo($bgcolor); ?>>
<td class="Style3"><?php echo $row["nom"]; ?>
<div id="blocinfo<?php echo($i); ?>" class="blocinfo">
<p><a href="./" title="Afficher les coordonnées" onmouseover="affichermasquer('tableinfos<?php echo($i); ?>');" onmouseout="affichermasquer('tableinfos<?php echo($i); ?>');">Détails</a></p>
<table id="tableinfos<?php echo($i); ?>" summary="" style="display: none">
<tr>
<td><?php echo $row["coordonnees"]; ?></td>
</tr>
</table>
</div>
</td>
<td align="center" class="Style2"><?php $row['Adresse']." ". $row['CP']." ". $row['VILLE'] ?></td>
</tr>
<?php
$i++;
}
?>
</table>
<?php
}
?>
</body>
</html>[/php]
Teste ça et reviens demander des explications si un point t'échappe.