Aller au contenu
View in the app

A better way to browse. Learn more.

Next

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[php] tableau et base de données

Featured Replies

Posté(e)

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 :yes:

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 !

:D

- edit de Quarky -

Ajout des balises code : c'est déjà un peu plus lisible :cartonrouge:

Posté(e)

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 )

Posté(e)

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

Archivé

Ce sujet est désormais archivé et ne peut plus recevoir de nouvelles réponses.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.