GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 05-Nov-2008, 16:07
stvalentine84 stvalentine84 is offline
New Member
 
Join Date: Nov 2008
Posts: 2
stvalentine84 is on a distinguished road
Question

Loading listbox with database tables


I am have some issues with loading my listbox with my database tables. I have a script that selects the correct database and then this page loads with just the tables that are loaded in that database.

anyhelp is appreciated. Thanks!!

PHP Code:

<html>
<head><title>List Tables</title></head>
<body>
<form method="POST" action="name.php"><div><center><p>Select Table
<input type="hidden" name="table_name" value="TABLE_names">
<SELECT NAME="Select_Table">
<?php
   $link = mysql_connect("localhost", "username", "password");
   mysql_select_db($_POST['Select_DB']);

   $query = "show tables";
   $result = mysql_query($query);
while($line=mysql_fetch_object($result)):
echo "<option value=\"$line->Table\">$line->Table</option>";
endwhile;
mysql_close($link);
mysql_free_result($result);
?>
</select>
<input type="submit" value="Submit"></center></div>
</form>
</body>
</html> 

  #2  
Old 05-Nov-2008, 19:15
TurboPT's Avatar
TurboPT TurboPT is offline
Senior Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 1,140
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: Loading listbox with database tables


Are you 100% sure that the relevant column from the 'SHOW TABLES' command for the selected database is simply named 'Table'?
__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
  #3  
Old 06-Nov-2008, 09:06
stvalentine84 stvalentine84 is offline
New Member
 
Join Date: Nov 2008
Posts: 2
stvalentine84 is on a distinguished road

Re: Loading listbox with database tables


I came up with this to get the database name and then pass the DB name to the table script so that I cam able to look up the tables from the selected database. However my script for my table is not working correctly and will not populate the listbox. This script however is very similar in function but the list box is not working. Thanks for the help

PHP Code:

<html>
<head><title>List DB</title></head>
<body>
<form method="POST" action="sub.php"><div><center><p>Select DataBase
<input type="hidden" name="db_name" value="DB_names">
<SELECT NAME="Select_DB">
<?php

$conn = @mysql_connect( 'localhost', 'username', 'pass' )
or die( mysql_errno().': '.mysql_error());
$result = mysql_list_dbs( $conn );

while( $row = mysql_fetch_object( $result ) ):
echo "<option value=\"$row->Database\">$row->Database</option>";
endwhile;

// Free resources / close MySQL Connection
mysql_free_result( $result );
mysql_close( $conn );

?>
</select>
<input type="submit" value="Submit"></center></div>
</form>
</body>
</html> 

  #4  
Old 06-Nov-2008, 20:09
TurboPT's Avatar
TurboPT TurboPT is offline
Senior Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 1,140
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: Loading listbox with database tables


The reason I asked "are you 100% sure..." about the column referenced by your object is because 'Table' is NOT the column label returned with the SHOW TABLES query, see this:
Code:
mysql> use mysql Database changed mysql> show tables; +---------------------------+ | Tables_in_mysql | +---------------------------+ | columns_priv | | db | | func | | help_category | | help_keyword | | help_relation | | help_topic | | host | | proc | | procs_priv | | tables_priv | | time_zone | | time_zone_leap_second | | time_zone_name | | time_zone_transition | | time_zone_transition_type | | user | +---------------------------+ 17 rows in set (0.00 sec)
So, based on that, you were closer the first time, but just a bit off handling the column label at the while loop. Here's the PHP code from the FIRST post at the loop with a little rework: [your colon syntax at the loop was strange for me -- I only use curly-braces { } ]
PHP Code:

<?php
  // ...
$show_tables_column_label = "Tables_in_" . $_POST['Select_DB'];

while( $line = mysql_fetch_object($result) )
{
    $Table = $line->$show_tables_column_label;
    echo "<option value=\"$Table\">$Table</option>";
}
  // ...
?>

HTH
__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
 
 

Recent GIDBlogProblems with the Navy (Chiefs) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Restore Database ajitham .NET Forum 2 16-Feb-2006 06:09
Question about loading php into tables or css pcxgamer Web Design Forum 6 17-Sep-2005 22:08
Add/Remove Database tables dynamically from workspace abhi MS Visual C++ / MFC Forum 0 22-Jun-2005 07:10
Limit combo box and date time picker choice according to database created in folder shinyhui C++ Forum 0 22-Feb-2005 21:16
Limit combo box and date time picker choice according to database created in folder shinyhui MS Visual C++ / MFC Forum 0 22-Feb-2005 03:13

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 10:27.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.