Last active
December 15, 2015 18:09
-
-
Save yooslim/5301564 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Tableau contenant la liste des tables | |
$mesTables = array('Livres', 'Auteurs', 'Exemplaires', 'AuteursDe'); | |
//Definition de la table choisis, si elle existe bien évidement | |
if(isset($_POST['maTable']) AND array_key_exists($_POST['maTable'], $mesTables)) $tableChoisi = $_POST['maTable']; | |
else $tableChoisi = null; | |
//Connexion a la base de données | |
$link = mysql_connect("", "", "") or die("Impossible de se connecter."); | |
mysql_select_db("", $link) or die ("Impossible de trouver la base de données."); | |
?> | |
<form method="POST" action="#"> | |
<p>Quelle table voulez vous afficher ? </p> | |
<select name="table"> | |
<?php | |
foreach($mesTables AS $id=>$value) { | |
if($tableChoisi == $id) echo '<option value="'.$id.'" selected>'.$value.'</option>'; | |
else echo '<option value="'.$id.'">'.$value.'</option>'; | |
} | |
?> | |
</select> | |
<input type="submit" value="Envoyer" name="ok" /> | |
</form> | |
<?php if($tableChoisi != null) { ?> | |
<form> | |
<select name="listName"> | |
<?php | |
$resultat = mysql_query('SELECT * FROM ' . $mesTables[$tableChoisi]); | |
while($data = mysql_fetch_assoc($resultat)) { | |
echo '<option value="'.$data['champ1'].'">'.$data['champ2'].'</option>'; | |
} | |
?> | |
</select> | |
</form> | |
<?php } ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment