September 22, 200619 yr Bonjour tout le monde ! Voilà en fait j'ai un tableau remplit via une base de données et je voudrais récupérer une valeur (la référence) sur la ligne du tableau où l'utilisateur va cliquer pour l'envoyer à une autre page. Cependant je ne sais pas comment faire pour récupérer cette valeur alors si vous pouviez éclairer ma lanterne Voici le code de mon tableau : echo "<center><TABLE bgcolor='#DDDDDD' bordercolor='blue' border=2 cellpadding=10>"; echo "<tr><th>ID </th><th> Catégorie </th><th> Produit </th><th> Nom </th><th> Description </th><th>Tarif </th><th> Référence </th><th>Photo</th><th>Achat immédiat </th></tr>"; while($row = mysql_fetch_row($result)){ echo "<tr><td><center> $row[0] </center></td><td><center> $row[1] </center></td><td><center> $row[2] </center></td><td><center> $row[3] </center></td><td><center> $row[4] </center></td><td><center> $row[5]€ </center></td><td><center> $row[6] </td></center><td><IMG SRC='$row[7]'></td><td><center><form method='POST' name='ref'><Input type='button' value='Achat' onClick=document.location.href='http://localhost/r=rub7_1.php'></form></center></td></tr>";} Merci d'avance ! - edit de Quarky - Ajout des balises code : c'est déjà un peu plus lisible
September 22, 200619 yr Il faudrait commencer par organiser ton code (tabulation...) et surtout ne pas abuser des echo Par exemple la première ligne tu peux très bien fermé ta balise php avant. Dans ce genre là quoi : ton php avant .... ?> <center> <TABLE bgcolor='#DDDDDD' bordercolor='blue' border=2 cellpadding=10> <tr> <th>ID </th> <th> Catégorie </th> <th> Produit </th> <th> Nom </th> <th> Description </th> <th>Tarif </th> <th> Référence </th> <th>Photo</th> <th>Achat immédiat </th> </tr> <?php while($row = mysql_fetch_row($result)) { ?> <tr> <td><center><?= $row[0] ?></center></td> <td><center><?= $row[1] ?></center></td> <td><center><?= $row[2] ?></center></td> <td><center><?= $row[3] ?></center></td> <td><center><?= $row[4] ?></center></td> <td><center><?= $row[5]¤ ?></center></td> <td><center><?= $row[6] ?></center></td> <td><?= <IMG SRC="$row[7]"/> ?></td> <td><center><form method='POST' name='ref'><Input type='button' value='Achat' onClick=document.location.href='http://localhost/r=rub7_1.php'></form></center></td> </tr> <?php } ?> </TABLE> </center> c'est déjà beaucoup plus propore et surtout correct niveau syntaxe php ( <?= équivaut à <?php echo )
September 24, 200619 yr Salut, une solution serait de passer par un lien hypertexte: en cliquant sur le lien, tu enverras l'id de la ligne. Ca donnerait quelque chose comme ca: ton php avant .... ?> <center> <TABLE bgcolor='#DDDDDD' bordercolor='blue' border=2 cellpadding=10> <tr> <th>ID </th> <th> Catégorie </th> <th> Produit </th> <th> Nom </th> <th> Description </th> <th>Tarif </th> <th> Référence </th> <th>Photo</th> <th>Achat immédiat </th> </tr> <?php while($row = mysql_fetch_row($result)) { ?> <tr> <td><center><a href="page.php?id=<?php echo $row[0]; ?>" title="Lien"><?= $row[0] ?></a></center></td> <td><center><?= $row[1] ?></center></td> <td><center><?= $row[2] ?></center></td> <td><center><?= $row[3] ?></center></td> <td><center><?= $row[4] ?></center></td> <td><center><?= $row[5]¤ ?></center></td> <td><center><?= $row[6] ?></center></td> <td><?= <IMG SRC="$row[7]"/> ?></td> <td><center><form method='POST' name='ref'><Input type='button' value='Achat' onClick=document.location.href='http://localhost/r=rub7_1.php'></form></center></td> </tr> <?php } ?> </TABLE> </center> Comme tu peux le constater, j'ai rajouté une balise sur la case qui contient l'id, ainsi en cliquant dessus, on est renvoyé vers la page (il te faudra toutefois adapter l'url en fonction de tes besoins). P.S.: je te conseille de lire ce topic, en ce qui concerne le code (X)HTML propre
Archived
This topic is now archived and is closed to further replies.