SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2006
    Location
    UK
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    mysql_fetch_field query

    I am developing a website that requires a lot of admin forms and want to simplify how I create them.

    What I would like to do is use the mysql_fetch_field function to get info about the structure of the database table that the form info will be inserted into.

    Once I have the name for the each of the table fields, I have the name for each of the form fields etc.

    I was hoping to use max_length of the field with an if / else to decide between an input or a textarea in the form. However I now realise that this is the length of the longest value not the maximum length specified when the table was created.

    If anyone has any ideas for how I could interrogate the database to find out whether a field is char(50) and or say char(150), I'd be very grateful.

    Hope this makes sense!

  2. #2
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Funny you say that, I use a similar system but I define the form elements in an ini file.

    eg people.boot.ini
    Code:
    ;<?php exit(' you won\'t see my ini file'); ?>
    ; Bootstrap file for simple models
    ; Options for PDO are : INT STR NULL BOOL LOB
    ; params : PDO - field_type - size - HTML_Label
    
    [attributes]
    	
    id				= INT
    first_name		 	= STR-text-40-First name 
    last_name		 	= STR-text-40-Family name 
    description		 	= STR-textarea-400-Describe your complaint
    I'd like to generate the bare bones of that automatically from a table too.

    FWIW this file does 2 things, enables some simple database CRUD, and helps me generate simple form elements.

    $arr( 'first_name' , 'last_name' ) ;

    echo $this->generateFormElements( $arr ) ;

    I think total form element generation, such as you seem to mean, is not granular enough - this leaves plenty of override.

    Textarea 1 might be just that, where Textarea2 might need WYSIWYG controls adding to it, etc etc.

  3. #3
    SitePoint Zealot
    Join Date
    Aug 2009
    Posts
    122
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can run the following SQL statement to obtain info about your column names/types/length:

    Code:
    DESCRIBE my_table_name
    more details at: http://dev.mysql.com/doc/refman/5.0/en/describe.html


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •