Jump to content

Show some tables from mysql database


kristian_gl

Recommended Posts

Hello, need to show some of the tables in my database in a list/meny. At any given time I don't know how many tables there are in the DB, and what names they got, only which tables I don't wanna show (which are always the same).

 

In the code below, I manage to show all the tables:

 

$sql = "SHOW TABLES FROM oddl";
$result = mysql_query($sql);
?>
<form method="POST" action ="../admin/forhaandsvisning.php"> 
<p><select name="undersokelser" size="15" id="undersokelser">
          
<?php
	  while($row = mysql_fetch_row($result))
	  {
?>
  
<option value="<?php echo $row[0];?>"><?php echo $row[0];?></option>

<?php		
}
?>
</select>  

 

Any ideas?

Link to comment
https://forums.phpfreaks.com/topic/200697-show-some-tables-from-mysql-database/
Share on other sites

Untested, but it should work...

$x = array() // fill this array with the names of  tables not to show

$sql = "SHOW TABLES FROM oddl";
$result = mysql_query($sql);
$i=0;
while($row = mysql_fetch_array($result)){
  $y[$i] = $row['0']; // in the row[] it should be the number that is the field containing the table name
$i++;
}
$z = array_diff($y, $x); // this produces an array of table names NOT in the exclude list
$num = count($z); // the number of table names to be used

?>
<form method="POST" action ="../admin/forhaandsvisning.php"> 
<p><select name="undersokelser" size="15" id="undersokelser">
<?php
$i = 0;
while($i<$num) {
?>
<option value="<?php echo $z[$i];?>"><?php echo $z[$i];?></option><br>
<?php 
  $i++;
}
?>
</select> 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.