View Full Version : Select Table from a dropdown to pass onto another php page

02-23-2010, 09:49 PM

At current, this is my php for one of my php pages, it gets all the values from a certain value


$host=""; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name=""; // Database name
$tbl_name="GENERIC_TRACKING_MATRIX"; // Table name

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

// Retrieve data from database
$sql="SELECT * FROM $tbl_name";

// Start looping rows in mysql database.
<table><? echo $rows['Spec_Hand']; ?>, <? echo $rows['more like this']; ?></table>
// close while loop

// close connection

What i need help is that, i have 2 more tables with different values in it. In the above code, i mentioned 1 of my table as GENERIC_TRACKING_MATRIX, and i have 2 more like GENERIC_TRACKING_NEW and GENERIC_TRACKING_TEST.

before i access this page, i would like to have a dropdown showing all 3 tables and based on the selection, the above tbl_name will be replaced and the page is shown.

thank you for your help in advance.

02-23-2010, 10:01 PM
Sounds like javascript if you want it to instantly change it without going to another page.

Of course you should be able to point the table name to a select box, so on the page, once you select it, it reloads the page and updates it.

02-23-2010, 10:04 PM
Yes, thats the method i like to use.
but code wise, i need help,

can you give me some sample code? thank you

02-23-2010, 11:06 PM
Finally Got it !

i used $tbl_name=$_REQUEST['flight']; for selecting what table ?

then, in the main page, i used the below

<form method="POST" action="middle1.php">

<p><select size="1" onchange="this.form.submit();" name="flight">