I need help with very complex query

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
hi all,

I hope it is easier for you to answer than for me trying to explain

In a database I have some tables , each one has some mandatory fields
at the beginning and a couple at the end.
In the middle each table can have some additional fields from 0 to n
depending on how many fields have been inserted by who created the

Now, I need to set up a script which ,after receiving from a form the
table name, can print the first known fields,and all  the additional
ones , but I don' t want it to show the last 2 columns of the table
because they store sensitive or useless contents.

any tips ?  



Re: I need help with very complex query

johnny wrote:
Quoted text here. Click to load it
Sounds like you have a database design problem more than a query  
problem. With the limited details you have provided, I would suggest  
something like the following:

1. have a table that contains the mandatory fields and the private ones.  
Let's call this one table 'A'.
2. make sure that each row in the table has a unique id (in mysql, look  
at the auto_increment feature)
3. create a second table, 'B', that will contain the arbitrary data.  
Each row in B will contain the argument value and the id from the row in  
table A that is relates to. So, you have 0 to n rows in B referencing  
the unique id of a row in A.

This lets you have an arbitrary number of fields in B for each entry in  
A. Also, if you name the columns in A in  your SQL query instead of  
using '*', you can have SQL ignore the private fields on the end.

If this helps, I would suggest you spend a little time looking at  
database design and the capabilities of the SQL language.


Re: I need help with very complex query

David Haynes wrote:

hi David, thanks you made me realize that I already had a way to do
that simpler.

Ok , just to let you know, In my spare time I am making a sort of CRM

So I have a script to create a contact list as a new table, the table
can have just an email field but also others such as name, address and
so on.

Anyway, when I create a new table I also add its name and a description
into another table which lists all the contact lists , so I could just
have to add a field to this "list of lists" and insert into that column
a comma separated string of all the fields of the new table .

Then , of course, I can print the fields I want  to see the records,
delete, update one of them and so on...

It sound quite simple this way, isn't it ?


Quoted text here. Click to load it

Re: I need help with very complex query

johnny wrote:
Quoted text here. Click to load it

You can get a list of fields in a table by running a query like this:

SHOW FIELDS FROM [table_name];


SHOW COLUMNS FROM [table_name];

Then you can write all names into an array and simply skip the last two
when outputting the list into the browser...  


Re: I need help with very complex query

Keep in mind, that these column and DB-structure operations are usualy  
DB-specific, commands working in one DB-platform will not work in other  

NC wrote:
Quoted text here. Click to load it

Site Timeline