hi
I need to run this query:
select distinct db from mysql.db where select_priv = 'y' and user = 'jblogs';
and take the database names and put them in a drop down box so that when a database name is selected, the table names are displayed underneath it. Any ideas?
Putting query results into a drop down box....
Moderator: General Moderators
-
struggling_student
- Forum Newbie
- Posts: 15
- Joined: Mon Feb 23, 2004 3:51 pm
- Lord Sauron
- Forum Commoner
- Posts: 85
- Joined: Tue Apr 20, 2004 5:53 am
- Location: Tilburg, NL
Yep, I do have ideas 
Although it would help if I would understand your DB-structure. You're using strange names. 'db' is the column containing the table-names? And mysql.db is a table containing the information of all databases?
Something like this (guess it is not completely error-free)
Although it would help if I would understand your DB-structure. You're using strange names. 'db' is the column containing the table-names? And mysql.db is a table containing the information of all databases?
Something like this (guess it is not completely error-free)
Code: Select all
<?php
$result = mysql_query("SELECT distinct db FROM mysql.db where select_priv = 'y' and user = 'jblogs';",mySQLConnection) OR die("wrong query");
$databNames = mysql_fetch_row($result);
IF (empty($databNames)) {
print("No databases available\n");
} // Close if
ELSE {
// Create form
print("<FORM name="displayTableNames" method='POST' action="displayNames.php?dbNames=$dbNames">\n\n");
print("<SELECT CLASS="selectBox" NAME='dbNames' TABINDEX="1" SIZE="2">\n");
while(!empty($databNames)) {
print("<OPTION VALUE='$name' SELECTED>".$databNames[0]."</OPTION>\n");
$databNames = mysql_fetch_assoc($result);
} // Close while loop
print("</SELECT>\n");
print("<INPUT class="button" type="submit" value="Show names" name="showNamesButton" tabindex="3">\n");
print("</FORM>\n");
} // Close else
?>Code: Select all
<?php
// displayNames.php
IF (!empty($dbNames)) {
// Query for searching the table names of this database
$tableNames = "SELECT tableNames FROM Database WHERE Database=".$dbNames.";"
ECHO $dbNames;
ECHO $row = mysql_fetch_row($tableNames)
ECHO "<TABLE">
ECHO "<TR>";
while (!empty($row))) {
ECHO "<TD>";
ECHO $row."<BR>";
$row = mysql_fetch_row($tableNames);
ECHO "</TD>";
}
ECHO "</TR>";
ECHO "</TABLE">
}
?>- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Code: Select all
SHOW DATABASES- Lord Sauron
- Forum Commoner
- Posts: 85
- Joined: Tue Apr 20, 2004 5:53 am
- Location: Tilburg, NL