Adding Field to Table

Discussion in 'PHP' started by adamjblakey, Aug 5, 2009.

  1. #1
    Hi,

    I want to add a field in a table which i am doing by:

    mysql_query("ALTER TABLE `site_details` ADD vat_no int(15)"); 
    PHP:
    Which is fine to add the field but i was wondering if there is a way in adding this after another field that i specify?

    Cheers,
    Adam
     
    adamjblakey, Aug 5, 2009 IP
  2. dimitar christoff

    dimitar christoff Active Member

    Messages:
    882
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    90
    #2
    yes

    alter table blah add foo varchar(20) after bar, resulting in:

    bar something
    foo varchar(20)

    :)
     
    dimitar christoff, Aug 5, 2009 IP
  3. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #3
    If you want to learn some mysql, a good thing is to look at the query that phpmyadmin generates. So create the table in phpmyadmin, and look at the resulting sql.
     
    premiumscripts, Aug 5, 2009 IP
  4. khajeya

    khajeya Member

    Messages:
    256
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    28
    #4
    dimitar christoff is right, and I agree with premiumscripts, if you want to learn some mysql syntax, you can use phpmyadmin and look at generated query.. :D

    for add field in table after a field, you can user this syntax (for example, you add field named new_field_name for varchar as type data in table table_name, and insert it after field old_field

     
    khajeya, Aug 5, 2009 IP