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?

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>";

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.