Jras Posted March 29, 2007 Share Posted March 29, 2007 I've written a code that runs a 'SHOW DATABASES' query on my mysql server and lists the results(the names of the databases on my server) in a dynamically generated dropdown box, and it works just fine, using the following code: echo "<select name='databaseselect'>"; $dblist = mysql_query('SHOW DATABASES'); while ($row = mysql_fetch_row($dblist)) { echo "<option value='$row2[0]'>$row2[0]</option>"; } echo "</select>"; The problem is that it lists ALL of the databases on my server - that's two of my own user-created databases, and the two default databases that come with the mysql server - 'information_schema' and 'mysql'. What I want to do is to, after running the 'SHOW DATABASES' query, eliminate those two databases from appearing in the dropdown box, because I don't want anyone to see them, as they're useless to anybody else. I've tried to do it using a series of strcmp codes and if statement, like this, but it hasn't worked: echo "<select name='databaseselect'>"; $dblist = mysql_query('SHOW DATABASES'); while ($row = mysql_fetch_row($dblist)) { if (strcmp($row2[0], "information_schema")==0) { echo "";} if (strcmp($row2[0], "mysql")==0) { echo "";} else echo "<option value='$row2[0]'>$row2[0]</option>"; } echo "</select>"; When I do this, only the 'mysql' database is removed from the dropdown box. The 'information_schema' database still appears in the dropdown box. What I am I doing wrong? And is there another way to do this that I'm not thinking of? If so, do tell. If not, what's wrong with my code above? Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted March 29, 2007 Share Posted March 29, 2007 echo "<select name='databaseselect'>"; $dblist = mysql_query('SHOW DATABASES'); while ($row = mysql_fetch_row($dblist)) { if ($row[0] != "information_schema" && $row[0] != "mysql") { echo "<option value='$row2[0]'>$row2[0]</option>"; } } echo "</select>"; Quote Link to comment 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.