Code to find all database fields starting with letter a or b

Discussion in 'PHP' started by mnymkr, Jun 23, 2008.

  1. #1
    is there php code or a swl query that will allow you to pull database fields that only begin with a certian letter?
     
    mnymkr, Jun 23, 2008 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    Possibly something like:

    SHOW COLUMNS FROM table;

    Not sure if the conditional will work... Requires MySQL 5.0.3 and up...

    SHOW COLUMNS FROM table WHERE Field LIKE 'A%';

    I do know that you cannot sort be names. You may have to program that into your code's logic.

    Also this may help some: http://se2.php.net/manual/en/function.mysql-fetch-field.php
     
    jestep, Jun 23, 2008 IP
  3. mnymkr

    mnymkr Well-Known Member

    Messages:
    2,328
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    120
    #3
    what do you mean cannot sort by names?
     
    mnymkr, Jun 23, 2008 IP
  4. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #4
    For a SHOW COLUMNS Query, sorting isn't allowed, (IE: SHOW COLUMNS FROM table ORDER BY Field ASC).
     
    jestep, Jun 23, 2008 IP