Looping through TABLES for given field name not records

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Borojimmy
Forum Newbie
Posts: 12
Joined: Fri Mar 20, 2009 2:08 pm

Looping through TABLES for given field name not records

Post by Borojimmy »

this might sound like a weird question but the answer would make my life a whole lot easier.

I am writing a CMS and certain MySQL tables are linked to PHP classes (as the norm), but what I want to do is to add a particular 'Flag' to certain tables to show that the records within can be used to build menus, so 'Pages' can be a menu, 'Users' can be a sub menu 'products' can be a menu, but 'user_address' wouldnt, once I can see that a table could contain a record named 'is_menu'

so it would be something like:

SHOW TABLES WHERE COLUMN LIKE %is_menu%

Ive tried using %is_menu% , vis_menu% & is_menu and none give a return value (using sing;e quotes of course!),

any help would be apprectiated.


Jimmy
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: Looping through TABLES for given field name not records

Post by Eran »

I would suggest avoiding this approach. You are trying to add meta-data about a table (should it be in a menu) on a column level. This means every row in those tables would contain this information. A better approach would be to write the query that builds the menu from the tables that participate - ie. have that logic in code and not in the database (where it has no natural place).
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Looping through TABLES for given field name not records

Post by califdon »

I agree with pytrin, but if you need to have this information, the logical place to store this info is another table that simply has a record for each table that can be a menu. Then you can search that table to determine whether another table is in that category. Of course, this requires that this meta-table must be maintained as you make changes in your schema that affect those conditions.
Post Reply