Skip to content

Instantly share code, notes, and snippets.

@yooslim
Last active December 15, 2015 18:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yooslim/5301564 to your computer and use it in GitHub Desktop.
Save yooslim/5301564 to your computer and use it in GitHub Desktop.
<?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