kristian_gl Posted May 4, 2010 Share Posted May 4, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/200697-show-some-tables-from-mysql-database/ Share on other sites More sharing options...
litebearer Posted May 4, 2010 Share Posted May 4, 2010 $x = array of table not to show $y = array of all tables $z = array_diff($y,$x) these are the ones you want to show Quote Link to comment https://forums.phpfreaks.com/topic/200697-show-some-tables-from-mysql-database/#findComment-1053179 Share on other sites More sharing options...
kristian_gl Posted May 4, 2010 Author Share Posted May 4, 2010 can you show me in the code where to put it. Sorry, but i'm not that good with PHP Quote Link to comment https://forums.phpfreaks.com/topic/200697-show-some-tables-from-mysql-database/#findComment-1053181 Share on other sites More sharing options...
litebearer Posted May 4, 2010 Share Posted May 4, 2010 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> Quote Link to comment https://forums.phpfreaks.com/topic/200697-show-some-tables-from-mysql-database/#findComment-1053217 Share on other sites More sharing options...
kristian_gl Posted May 4, 2010 Author Share Posted May 4, 2010 thanks, that worked just fine. just one tiny problem, in the list/meny, there are some empty spaces, which you can select where the tables that are not showing just to be Quote Link to comment https://forums.phpfreaks.com/topic/200697-show-some-tables-from-mysql-database/#findComment-1053294 Share on other sites More sharing options...
litebearer Posted May 5, 2010 Share Posted May 5, 2010 Not sure, but you may need to reindex the $z array Quote Link to comment https://forums.phpfreaks.com/topic/200697-show-some-tables-from-mysql-database/#findComment-1053560 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.