SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Guru worchyld's Avatar
    Join Date
    Jul 2003
    Location
    Newcastle upon Tyne
    Posts
    909
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Generate form gadgets based upon mysql database info?

    I'm wondering if there is a class that will generate form gadgets (preferably XHTML valid) based upon mysql database row info.

    For example, I'm finding it very tedious to constantly write:

    Code:
    # pseduocode
         print '<input type="text" name="forename" value="'.$row->forename.' />';
    For every row that appears in my table. Isn't there a way to say, do this kind of thing?

    Code:
    # pseduocode
    
    $g = new gadget();
    $db =  new db();
    $sql = 'SELECT * FROM customers';
    $res = $db->query( $sql );
    foreach ($res as $row) {
         print $g->inputTag ( $row->$field->type, $row->$field->data );   
    }
    The problem I've had is that you can't use "mysql_fetch_field()" until after the result and not whilst you're in the loop.

    What this means is that I'm resorting to use two queries to do one thing, which is bad practise.

    Secondly, this whole concept will, in theory, only work on one table and not on joins... although, I could be mistaken.

    The Idea

    The idea is that I don't have to repeat myself, or add a new input tag every time I add a new field to my database.... I'd rather a class did all the work, figure out what gadget to use (ie: hidden, textarea, input, etc) and then display that.

    The problems

    The only problem I can see with doing it this way is that a table may have lots of subkeys or secondary keys (also known as foriegn keys) and php/mysql won't know if it should make them hidden or not, or perhaps you may not want *all* the respective fields displayed for one reason or another.

    Anyway, to summarize; is it possible to create form gadgets based upon the mysql database info?

  2. #2
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,631
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Ian Anderson
    www.siteguru.co.uk


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
  •