creating vars on the fly

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mike B

    creating vars on the fly

    Hi everyone,


    I have a project that I'm working in which the user is allowed to
    create and add columns to certain tables in mysql. After they add
    them, I need to be able to display them in a form so I can use them.
    Now, that part isn't a problem, but what I'm having a problem w/ is
    that when I submit them through the form, how can I process all the
    fields dynamically. The user could add 20 fields so how in my code
    could I handle that. If anyone could help me out I would appreciate
    it or if you need more info or I'm not making sense let me know.
    LAMP environment, PHP 4.2.3 MySQL 4.0.12

    TIA
    Mike B
  • Ken Robinson

    #2
    Re: creating vars on the fly

    meadmaker1977@y ahoo.com (Mike B) wrote in
    news:7039e944.0 307190625.7fa1e e1b@posting.goo gle.com:
    [color=blue]
    > Hi everyone,
    >
    >
    > I have a project that I'm working in which the user is allowed to
    > create and add columns to certain tables in mysql. After they add
    > them, I need to be able to display them in a form so I can use them.
    > Now, that part isn't a problem, but what I'm having a problem w/ is
    > that when I submit them through the form, how can I process all the
    > fields dynamically. The user could add 20 fields so how in my code
    > could I handle that. If anyone could help me out I would appreciate
    > it or if you need more info or I'm not making sense let me know.
    > LAMP environment, PHP 4.2.3 MySQL 4.0.12[/color]

    Here's some code that should help you.
    $query = "Your query here";
    $result = @mysql_query ($query);
    while ($row = mysql_fetch_arr ay($result,MYSQ L_ASSOC))
    {
    while(list($key ,$val) = each($row)) {
    echo '<input type=text name=$key
    value="'.htmlsp ecialchars(stri pslashes($row[$key])).'"> '."\n";
    }
    echo "\n";
    }


    The key is to get the array return by MySQL to be an associative array
    that has the field names as indices to the array.

    Ken Robinson
    KIS Web Design

    Comment

    • MeerKat

      #3
      Re: creating vars on the fly

      mysql_list_fiel ds() could help.

      See the example at


      Mike B wrote:[color=blue]
      > Hi everyone,
      >
      >
      > I have a project that I'm working in which the user is allowed to
      > create and add columns to certain tables in mysql. After they add
      > them, I need to be able to display them in a form so I can use them.
      > Now, that part isn't a problem, but what I'm having a problem w/ is
      > that when I submit them through the form, how can I process all the
      > fields dynamically. The user could add 20 fields so how in my code
      > could I handle that. If anyone could help me out I would appreciate
      > it or if you need more info or I'm not making sense let me know.
      > LAMP environment, PHP 4.2.3 MySQL 4.0.12
      >
      > TIA
      > Mike B[/color]

      --
      MeerKat

      Comment

      Working...