Jump to content

Adding "descriptions" to table columns for interface purpouses


logansama

Recommended Posts

First off, i am still new with the forum thing so if this should be under a different section please tell me! Without the throwing of fruit and veg!  ;D

I am making a html based personnel management system. Nothing big.
I am using a combination of OOP based JS and PHP as well as some Ajax structures.

The idea is user selects an employee then does a search of data concerning set employee.
The call for data is sent from html via JS and Ajax to php, where data is retrieved, structured and sent back to JS classes that automatically builds a display interface showing the retrieved data.

<u>My problem is this:</u>
I would like to be able to retrieve a "description/comments" (for lack of better term) of a given column.
At present i need to hard code a <b>SWITCH</b> or <b>IF</b> or whatever to define a description for a column. By this i mean that IF column: fname is selected then the description is set to "First Name", IF column: telnum then set to "Contact Number" etc etc.

I would like to know if there is a way to make a description in the table on the column itself so that if i retrieve the value of column fname, then i can also get the "description" of the column?

<b>EXAMPLE CONCEPT:</b>
SELECT the value of column fname: "David" from table and SELECT the "description" of column fname: "First Name" from same table.

Then i can pass both back to JS and bobs-your-uncle i can build generic interface class to display "First Name: David"  8)

The closest i have been able to find is mysql_fetch_field, but as far as i have tried i cannot get it to assist me in this matter. Other ideas included making a sister-table witch has the "description" of each column, but doing this with ALL the tables is useless redundancy!
If you have an idea of what i should do, functions to use or a website to go to, any help will be much appreciated!

PS
I am not the best at describing what is in my head and its latish! :P So if you don't understand what i mean, please feel free to ask any questions! :)
Link to comment
Share on other sites

This is not me pushing the posts. Just adding extra discovery.

I have tried additional uses of mysql_fetch_field. By attempting to access the the value of "default" field. As is the example found on [URL=http://'http://www.php.net/manual/en/function.mysql-fetch-field.php']php.net - mysql_fetch_field[/URL]

Unfortunately i get ALL the info back from the result set concerning all the colums i use, EXCEPT the default's value. So now ia m officially stumped!!
Link to comment
Share on other sites

I don't see why you want to have these details in the DB... if you really must, make another table with mapping between fields & descriptions, load this into your script first, and then just use this mapping on the way out.  It should have little to do with how you query the DB.
Link to comment
Share on other sites

Yeah i know. Am doing something similar at present.
I just wanted to do it, because i really do not want to make extra tables or unnecessary code just to get two- or three worded descriptions!

I usually try to do things a tad differently! 
Thanks for the input though!! ;D
Link to comment
Share on other sites

Yeah have been thinking about it allot thus far. Will actually implement it that way! I have run out of any other option, beside hardcoding relations in the php, but that is just nasty and wrong!  :P

But (just in case) is there a special "structure"/"communication" (lack of terminology) that could be made between the table with the data and the table with corresponding 'descriptions'? I am not all that sure that a Primary-key/Foreign-key application could be used?!  ???
I am not yet all that expert with the building of database relations.

Thank you for assistance.
Link to comment
Share on other sites

Forgive the lack of understanding of term but do you mean DB abstraction layers? After reading your reply i googled a tad, and found that there are basically four types of abstraction layers:
  1.  A software library to connect to a database server and issue queries, fetch results etc.
  2. A software library to present a common API to different database servers.
  3. A software library to automatically generate portable SQL queries.
  4. A software library to map Object-Oriented Programming to a relational database (Object-Relational Mapping, or ORM)

Is this what you meant? I assume you have worked with these layers before. If so could you perhaps give me a starting point from where to work from? Some pointer or where you would start or website to read?  ??? ;D

Will continue the google search for now. And thank you for this nudge in a direction. Much appreciated!
Link to comment
Share on other sites

Yeah, I mean something like that -- basically, instead of having to pull your descriptions manually, you have your DB wrapper "wrap" your queries so that it happens automagically.  I can't really give you a starting pont since everything I've ever done w.r.t. MySQL has been written in Perl, not PHP.
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.