lien sélectif à partir de chacune des lignes d'un tableau
Bonjour,
J'obtiens un tableau d'enregistrements (MySQL) en utilisant do{ }while() en PHP.
Je souhaite qu'un clic sur chacune des lignes ouvre une fiche individuelle.Par :
Code:
$("tr").click(function(){$(location).attr('href',"reception.php?var=");});
j'obtiens bien la page d'affichage mais mes différents essais en JQUERY pour récupérer l'ID correspondant à chaque ligne restent vains.
Merci de l'éventuelle solution qui pourrait m'être proposée.
voir script complet ci-dessous :
Code:
1 2 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
| <?php require_once('../Connections/GACR.php'); ?>
<?php
mysql_select_db($database_GACR, $GACR);
$query_r1 = "SELECT * FROM adherents WHERE adherents.R<>22 AND adherents.R<>23 ORDER BY adherents.nom";
$r1 = mysql_query($query_r1, $GACR) or die(mysql_error());
$row_r1 = mysql_fetch_assoc($r1);
$totalRows_r1 = mysql_num_rows($r1);
isset($startRow_r1)? $orderNum=$startRow_r1:$orderNum=0;
?>
<!doctype html>
<html>
<head>
<meta charset="iso-8859-1">
<title>LeTableau</title>
<style type="text/css">
</style>
<script type="text/javascript" src="jquery-1.7.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("tr").mouseenter(function(){
$(this).css({"background-color":"#9cf"});
})
.mouseleave(function(){
$(this).css({"background-color":"#ffc"});
});
$("tr").click(function(){$(location).attr('href',"reception.php?var=<?php ?>");});
});
</script>
</head>
<body>
<table id="tab1">
<tr>
<th width="35" scope="col">N°</th>
<th width="70" scope="col">Id</th>
<th width="168" scope="col">Nom Prénom</th>
<th width="205" scope="col">Adresse</th>
<th width="114" scope="col">CP</th>
<th width="207" scope="col">Ville</th>
</tr>
<?php do { ?>
<tr>
<td><?php echo ++$orderNum; ?></td>
<td><?php echo $row_r1['id']; ?></td>
<td align="left"><strong><?php echo $row_r1['nom']; ?></strong> <?php echo $row_r1['prenom']; ?></td>
<td align="left"><?php echo $row_r1['adresse']; ?></td>
<td><?php echo $row_r1['code_postal']; ?></td>
<td align="left"><?php echo $row_r1['ville']; ?></td>
</tr>
<?php } while ($row_r1 = mysql_fetch_assoc($r1)); ?>
</table>
</body>
</html>
<?php
mysql_free_result($r1);
?> |
lien sélectif à partir de chacune des lignes d'un tableau
Merci à amoiraud et SpaceFrog d'avoir accepté de m'aider.
La solution de SpaceFrog émet pour var, émis en GET , une valeur indéfinie puisqu'il n'y a pas de lien avec la boucle PHP
La solution de amoiraud fonctionne mais je ne pensais pas pouvoir utiliser des sélecteurs et méthodes jquery qui ne soient encadrés par des des balises script javascript. serait-ce abuser que de solliciter une explication ?
merci encore