Jump to content

Trying to use strcmp to edit a dynamically generated dropdown...


Jras

Recommended Posts

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?

Link to comment
Share on other sites

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.