Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Quick MySQL/PHP question

  • 16-03-2006 1:08pm
    #1
    Registered Users, Registered Users 2 Posts: 1,821 ✭✭✭


    Is there anyway of printing the column headers from a MySQL table in PHP? Looked for it everywhere. Want it to simplify an UPDATE. Or if anyone has any other examples of an easier way of UPDATING wouldn't mind hearing them. Cheers.


Comments

  • Closed Accounts Posts: 756 ✭✭✭Zaph0d


    ALTER TABLE t1 CHANGE a b INTEGER;
    where t1 is the table name, a is the old column name, b is the new column name, INTEGER is the existing type of the column.

    UPDATE is for changing data (DML)
    ALTER TABLE is DDL


  • Moderators, Politics Moderators Posts: 41,224 Mod ✭✭✭✭Seth Brundle


    rename the column?
    ALTER TABLE employees CHANGE oldcolname newcolname OLDDEFINITION

    where oldcolname becomes newcolname. The employees table would no longer have a column named "oldcolname". You must also retain and include the old definition. e.g. VARCHAR(255)


  • Moderators, Politics Moderators Posts: 41,224 Mod ✭✭✭✭Seth Brundle


    darn! not quick enough!


  • Registered Users, Registered Users 2 Posts: 1,821 ✭✭✭Skud


    cheers lads but I wasn't specific enough. I want the column name to assist an update of a row like

    TABLE branch

    Branch_Num | Street | City | Pcode | Tel_No
    Branch 5 | Dam st | Dub | 00990 | 01xxxx

    so I want to have
    $query = "UPDATE $tableoption SET $key1 = $key3 WHERE $key1 = $key2; ";


    Where $tableoption is selected from a dropdown. (in this case it'd be branch)
    $key1 is a column header selected from a dropdown. (Branch_Num, Street, City, Pcode, Tel_No)
    $key3 is a new value.
    $key2 is the old value to be overwritten.

    So it'd be like the show tables command....


  • Closed Accounts Posts: 756 ✭✭✭Zaph0d


    Skud wrote:
    cheers lads but I wasn't specific enough. I want the column name to assist an update of a row like

    TABLE branch

    Branch_Num | Street | City | Pcode | Tel_No
    Branch 5 | Dam st | Dub | 00990 | 01xxxx

    so I want to have
    $query = "UPDATE $tableoption SET $key1 = $key3 WHERE $key1 = $key2; ";


    Where $tableoption is selected from a dropdown. (in this case it'd be branch)
    $key1 is a column header selected from a dropdown. (Branch_Num, Street, City, Pcode, Tel_No)
    $key3 is a new value.
    $key2 is the old value to be overwritten.

    So it'd be like the show tables command....
    You were specific. you asked a specifically different question and then edited your question to something completely different. Unless I am nuts which I am.

    OK here's the answer to question 2:
    use INFORMATION_SCHEMA views to get table names and other metadata from your database. This method works in the latest versions of mysql, sql server and oracle.

    To populate your dropdown of tables:
    SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES;
    

    To find the columns for a specific table:
    SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS
    WHERE TABLE_NAME = '<your chosen table>';
    


  • Advertisement
Advertisement