Hi all,
I want to make a <select> box with a few <options>. Every option is a table name in my database.
So for example, i have a databse called Forms: and Forms has the tables: Hosting, WebHosting, Users.
Now I want those table names in a <select> box, so for example:
<select>
<option>Hosting</option>
<option>Webhosting</option>
<option>Users</option>
</select>
When I click on a option in the list, I want to get some data from that table, so for example when i click on Users:
Name: RuubR
Age: 22
Country: Netherlands
Hope you guys know what i mean..^^
Is something like this possible?
MySQL Table names
Started by RuubR, Mar 29 2010 05:01 AM
3 replies to this topic
#1
Posted 29 March 2010 - 05:01 AM
|
|
|
#2
Posted 29 March 2010 - 09:19 AM
With this SQL-Query you can list the tables as far I know.
After it you should iterate through it and generate HTML-Code.
SHOW TABLES FROM Forms;
After it you should iterate through it and generate HTML-Code.
#3
Posted 29 March 2010 - 11:49 AM
Something like this:
$result = mysql_query("SHOW TABLES FROM Forms");
if(mysql_num_rows($result) > 0)
{
echo "<select>";
while($row = mysql_fetch_row($result))
{
echo "<option>".$row[0]."</option>";
}
echo "</select>";
}
#4
Posted 31 March 2010 - 02:43 AM
<html>
<head>
<title>selection box with database</title>
</head>
<body>
<form action="selectprocess.php" method="POST">
<select name=selectdatabase>
<option value="images">Images</option>
<option value="movie">Movie</option>
<option value="movitype">MovieType</option>
<option value="people">People</option>
<option value="reviews">Reviews</option>
</select>
<input type="submit" />
</form>
</body>
</html>
//code of selectprocess.php
<?php
$db = mysql_connect('example.com', 'root', '********') or
die('Unable to connect check your connection parameters');
mysql_select_db("moviesite", $db) or die(mysql_error($db));
$val = $_POST['selectdatabase'];
$query = "SELECT * FROM $val";
$result = mysql_query($query, $db) or die(mysql_error($db));
while ($row = mysql_fetch_array($result)){
extract($row);
print_r($row);
}
?>
<head>
<title>selection box with database</title>
</head>
<body>
<form action="selectprocess.php" method="POST">
<select name=selectdatabase>
<option value="images">Images</option>
<option value="movie">Movie</option>
<option value="movitype">MovieType</option>
<option value="people">People</option>
<option value="reviews">Reviews</option>
</select>
<input type="submit" />
</form>
</body>
</html>
//code of selectprocess.php
<?php
$db = mysql_connect('example.com', 'root', '********') or
die('Unable to connect check your connection parameters');
mysql_select_db("moviesite", $db) or die(mysql_error($db));
$val = $_POST['selectdatabase'];
$query = "SELECT * FROM $val";
$result = mysql_query($query, $db) or die(mysql_error($db));
while ($row = mysql_fetch_array($result)){
extract($row);
print_r($row);
}
?>


Sign In
Create Account

Back to top









