Page 1 of 1

Query for Tables

Posted: Fri Sep 10, 2004 7:49 pm
by AliasBDI
I am wanting to get a dynamic list of TABLES in a Database. Is this possible? How would it look if it is possible?

Posted: Fri Sep 10, 2004 7:57 pm
by feyd

Code: Select all

SHOW TABLES

Posted: Fri Sep 10, 2004 8:44 pm
by AliasBDI
Fair enough. I'm trying to get the list of the tables into a multiple select form field:

Code: Select all

<select name="tablesї]" size="6" multiple="multiple" class="forms" id="tablesї]">
                  <option value="con_news">var_month</option>
                  <?php
do {  
?>
                  <option value="<?php echo $row_tableLISTї'id']?>"><?php echo $row_tableLISTї'id']?></option>
                  <?php
} while ($row_tableLIST = mysql_fetch_assoc($tableLIST));
  $rows = mysql_num_rows($tableLIST);
  if($rows > 0) {
      mysql_data_seek($tableLIST, 0);
	  $row_tableLIST = mysql_fetch_assoc($tableLIST);
  }
?>
Here is my query and connection code:

Code: Select all

<?php mysql_select_db($*****, $*******);
$query_tableLIST = "SHOW TABLES";
$tableLIST = mysql_query($query_tableLIST, $*****) or die(mysql_error());
$row_tableLIST = mysql_fetch_assoc($tableLIST);
$totalRows_tableLIST = mysql_num_rows($tableLIST); 

?>
I put **** on db name, disregard them.

I guess my question is, how would I echo the results?

Posted: Fri Sep 10, 2004 11:58 pm
by feyd
it's like any standard query for multiple records; run it in a fetching loop ;)

Posted: Sat Sep 11, 2004 8:08 am
by AliasBDI
I got it. Thanks for the help. I was confused because I thought that there should have been an echo field name. But that cleared it up. Thanks for the help again.

Here is the code for you readers:
QUERY CODE:

Code: Select all

<?php
mysql_select_db($databasename, $connect);
$query_queryLIST = "SHOW TABLES";
$queryLIST = mysql_query($query_queryLIST, $connect) or die(mysql_error());
$row_queryLIST = mysql_fetch_row($queryLIST);
$totalRows_queryLIST = mysql_num_rows($queryLIST);

mysql_free_result($queryLIST);
?>
ECHO RESULTS CODE:

Code: Select all

<?php
<?php
do {  
?>
                  <option value="<?php echo $row_queryLIST[0]; ?>"><?php echo $row_queryLIST[0]; ?></option>
                  <?php
} while ($row_queryLIST = mysql_fetch_row($queryLIST));
  $rows = mysql_num_rows($queryLIST);
  if($rows > 0) {
      mysql_data_seek($queryLIST, 0);
	  $row_queryLIST = mysql_fetch_row($queryLIST);
  }
?>