Jump to content

MySQL Table names

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
RuubR

RuubR

    Newbie

  • Members
  • Pip
  • 5 posts
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?

#2
hasher

hasher

    Newbie

  • Members
  • Pip
  • 3 posts
With this SQL-Query you can list the tables as far I know.

SHOW TABLES FROM Forms;

After it you should iterate through it and generate HTML-Code.

#3
Arctic Fire

Arctic Fire

    Learning Programmer

  • Members
  • PipPipPip
  • 48 posts
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
kalpana

kalpana

    Newbie

  • Members
  • Pip
  • 2 posts
<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);
}
?>