Jump to content

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> 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.