Puoi prendere spunto da questo codice scritto un po' in fretta:
Codice PHP:
<?php
$selTab = array("table1" => "", "table2" => "");
$select = "";
$data = "";
if (isset($_POST['submit'])) {
$table = $_POST['tables'];
$selTab[$table] = "selected";
$username = "..."; // DB username
$password = "..."; // DB password
$connect = mysql_connect("localhost", $username, $password);
$db = mysql_select_db("test", $connect);
$query = "SELECT id FROM $table";
$result = mysql_query($query, $connect) or die ("Error: ".mysql_error());
$select = "<select name='ids'>";
while ($record = mysql_fetch_array($result)) {
$select .= "<option value='$record[id]'>$record[id]</option>";
}
$select .= "</select>";
if (isset($_POST['ids'])) {
$id = $_POST['ids'];
$query = "SELECT * FROM $table WHERE id = $id";
$result = mysql_query($query, $connect) or die ("Error: ".mysql_error());
while ($record = mysql_fetch_array($result)) {
$data= $record["description"];
}
}
}
?>
<form method="post" action="index.php">
<select name="tables">
<option value="table1" <?php echo $selTab["table1"] ?>>table 1</option>
<option value="table2" <?php echo $selTab["table2"] ?>>table 2</option>
</select>
<?php echo $select; ?>
<input type="submit" name="submit" value="submit" />
<?php echo $data; ?>
</form>
nel DB di esempio ho creato due tabelle chiamate table1 e table2 entrambe con due colonne (id e description).
Ovviamente lo script è da migliorare e da adattare alle tue esigenze.
Ti consiglio inoltre di adattarlo affinchè utilizzi chiamate Ajax.