#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2000
    Location
    Milton, Ontario, Canada
    Posts
    4
    Rep Power
    0
    I am creating a GUI for a company for editing the database. The forms allow the user to input the amount of columns to be in the table as well as the table name. The next page brings up a form with as many text boxes as columns specified by the user. The problem comes in when I send this information to MySQL. I need to add the variables to the CREATE TABLE statement through another loop, but you can only have CREATE TABLE once. I figured a way to get around this was to create the table then loop the command to add a column at a time. Is there any way to add a column to a database?
  2. #2
  3. No Profile Picture
    ads
    Guest
    Devshed Newbie (0 - 499 posts)
    <?

    $hostname = "*****";
    $username = "*****";
    $password = "*****";
    $dbName = "*****";

    MYSQL_CONNECT($hostname, $username, $password) OR DIE("Unable to connect to database");

    @mysql_select_db("$dbName") or die("Unable to select database");

    $query = "ALTER table tablename ADD birthday DATE";


    $result = MYSQL_QUERY($query);

    PRINT "***** $result *******";

    PRINT "Your databse altered.";
    MYSQL_CLOSE();

    ?>

    This should work.
  4. #3
  5. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    18
    You can dynamically create you query:

    $query="create table $table_name (";
    for ($i=1;$i<=$numofcols;$i++)
    {
    $query.=$columdefinition . " ,";
    }

Similar Threads

  1. adding columns to a table
    By gordie in forum MySQL Help
    Replies: 2
    Last Post: January 25th, 2004, 01:51 AM
  2. adding data to 2 tables at the same time
    By bulletz in forum ASP Programming
    Replies: 1
    Last Post: December 29th, 2003, 12:13 AM
  3. sum of two columns from two tables
    By ironchef in forum Database Management
    Replies: 21
    Last Post: December 20th, 2003, 06:43 AM
  4. tables get corrupted
    By 90coders in forum MySQL Help
    Replies: 1
    Last Post: December 5th, 2003, 05:23 AM
  5. Adding float columns in MySQL problematic
    By john blue ;-) in forum MySQL Help
    Replies: 2
    Last Post: October 5th, 2003, 06:07 AM

IMN logo majestic logo threadwatch logo seochat tools logo