Probléme avec php et mysql
Fermé
lamou23
Messages postés
178
Date d'inscription
lundi 11 janvier 2010
Statut
Membre
Dernière intervention
21 mars 2011
-
14 juin 2010 à 20:45
avion-f16 Messages postés 19125 Date d'inscription dimanche 17 février 2008 Statut Contributeur Dernière intervention 23 mars 2023 - 14 juin 2010 à 22:46
avion-f16 Messages postés 19125 Date d'inscription dimanche 17 février 2008 Statut Contributeur Dernière intervention 23 mars 2023 - 14 juin 2010 à 22:46
A voir également:
- Probléme avec php et mysql
- Alert php ✓ - Forum PHP
- Header php - Astuces et Solutions
- Mysql download - Télécharger - Bases de données
- Undefined index php - Astuces et Solutions
- Retour a la ligne php ✓ - Forum PHP
3 réponses
avion-f16
Messages postés
19125
Date d'inscription
dimanche 17 février 2008
Statut
Contributeur
Dernière intervention
23 mars 2023
4 468
14 juin 2010 à 21:02
14 juin 2010 à 21:02
Ajoute un champ id (TINYINT, AUTO_INCREMENT et UNSIGNED) à ta table.
Pour lister les machines :
Dans afficher_se.php :
Pour lister les machines :
<form method="get" action="affiche_se.php">
<p>
<?php
$pdo = new PDO('mysql:host=localhost;dbname=ta_base','root','');
$sql = 'SELECT * FROM table';
$req = $pdo->query($sql);
echo '<select name="id">;'
while($machine = $req->fetch()) {
echo '<option value="'.$machine['id'].'">'.$machine["nom"].'</option>';
}
echo '</select>';
$req->closeCursor();
unset($pdo);
?>
</p>
<p>
<input type="submit" value="Afficher SE" />
</p>
</form>
Dans afficher_se.php :
<?php
if(isset($_GET['id']) && (int) $_GET['id'] > 0) {
$pdo = new PDO('mysql:host=localhost;dbname=ta_base','root','');
$sql = 'SELECT se FROM table WHERE id='.(int) $_GET['id'];
$req = $pdo->query($sql);
if($req->rowCount() > 0) {
$machine = $pdo->fetch();
echo 'Système d\'exploitation : '.$machine['se'];
} else {
echo 'Machine inexistante.';
}
$req->closeCursor();
unset($pdo);
} else {
echo 'Mauvaise URL.';
}
?>
lamou23
Messages postés
178
Date d'inscription
lundi 11 janvier 2010
Statut
Membre
Dernière intervention
21 mars 2011
14 juin 2010 à 21:11
14 juin 2010 à 21:11
est ce que c'est faisable sans rajouter id a la table,?
merci
merci
avion-f16
Messages postés
19125
Date d'inscription
dimanche 17 février 2008
Statut
Contributeur
Dernière intervention
23 mars 2023
4 468
14 juin 2010 à 22:46
14 juin 2010 à 22:46
Oui, mais il faudra passer le nom de la machine par GET.