Solved

hides more than 1 table from displaying in the dropdown.

Posted on 2009-06-27
2
192 Views
Last Modified: 2012-05-07
this code below hides 1 table from the database named field_types and displays the other tables in a dropdown. i want to hide one more table that should not be displayed in the dropdown. please help me.

otherwise for 1 table, the code is working exactly fine.
i think we need to do something on line 8
<select onchange="changeTargetURL(this);" action="default.php">

        <option targetURL="" selected="selected">Select</option>

        <option targetURL="new.php">create new</option>

		<option>---------------</option>

		<?php

			$res = mysql_query("show tables") or die(mysql_error());

			while ($row = mysql_fetch_array($res)){

			   if ($row[0] == 'field_types') continue;

			   $my_tables[] = $row[0];

			}

			foreach ($my_tables as $tablename){			

		?><option targetURL="<?php echo $tablename.".php"; ?>"><?php echo $tablename; ?></option><?php 			

		} ?>

</select>

Open in new window

0
Comment
Question by:designersx
  • 2
2 Comments
 
LVL 8

Expert Comment

by:fcardinaux
ID: 24727214
Put all the tables you need to hide in an array, and do this:

<select onchange="changeTargetURL(this);" action="default.php">

        <option targetURL="" selected="selected">Select</option>

        <option targetURL="new.php">create new</option>

                <option>---------------</option>

                <?php

                        $tables_to_hide = array('field_types', 'the_other_table');

                        $res = mysql_query("show tables") or die(mysql_error());

                        while ($row = mysql_fetch_array($res)){

                           if (in_array($row[0], $tables_to_hide) continue;

                           $my_tables[] = $row[0];

                        }

                        foreach ($my_tables as $tablename){                     

                ?><option targetURL="<?php echo $tablename.".php"; ?>"><?php echo $tablename; ?></option><?php                  

                } ?>

</select>

Open in new window

0
 
LVL 8

Accepted Solution

by:
fcardinaux earned 250 total points
ID: 24727218
Sorry, I forgot a parenthesis in my previous code:

<select onchange="changeTargetURL(this);" action="default.php">

        <option targetURL="" selected="selected">Select</option>

        <option targetURL="new.php">create new</option>

                <option>---------------</option>

                <?php

                        $tables_to_hide = array('field_types', 'the_other_table');

                        $res = mysql_query("show tables") or die(mysql_error());

                        while ($row = mysql_fetch_array($res)){

                           if (in_array($row[0], $tables_to_hide)) continue;

                           $my_tables[] = $row[0];

                        }

                        foreach ($my_tables as $tablename){                     

                ?><option targetURL="<?php echo $tablename.".php"; ?>"><?php echo $tablename; ?></option><?php                  

                } ?>

</select>

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
calculated column 12 74
what is best version of php to use 6 44
Form not operating correctly. 1 22
mcrypt_create_iv() is deprecated 4 69
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now