SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict dionsiseire's Avatar
    Join Date
    Apr 2005
    Location
    Dublin
    Posts
    334
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    get column names from query (adodb used)

    im looking to take in a query as a parameter ( its not that simple, but for now lets keep it that way)

    the query could be absolutely anything and i need to be able to pull out what columns have been queried so i can print them out

    any idea's?

  2. #2
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    453
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sounds like this post should be in "Classic ASP", if you are using an ADO Database. If you have installed the PDO and the appropriate drivers simply execute your query and get a valid resultset. Get a row via the PDO :: FETCH_ASSOC() function, which will retrieve a row in an associative array.
    A simple foreach loop will allow you to store or print all column values, which will be the array keys.
    Computers and Fire ...
    In the hands of the inexperienced or uneducated,
    the results can be disastrous.
    While the professional can tame, master even conquer.

  3. #3
    SitePoint Addict dionsiseire's Avatar
    Join Date
    Apr 2005
    Location
    Dublin
    Posts
    334
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no no im using ADODB for PHP

    i will try the assoc array idea and try the keys

    thanks, although you intended this for ASP, the idea itself may work

  4. #4
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    453
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I missed the documentation on it the first time, but from what I have just read.
    Simply retrieve a valid recordset then use mysql_fetch_assoc() to retrieve a row. The key values( column names) can f=be extracted using the foreach loop.
    PHP Code:
    $db->SetFetchMode(ADODB_FETCH_ASSOC);
    $rs $db->Execute($query);
    foreach( 
    $rs as $k => $v ){
        echo 
    "Column name is : $k";

    Computers and Fire ...
    In the hands of the inexperienced or uneducated,
    the results can be disastrous.
    While the professional can tame, master even conquer.

  5. #5
    SitePoint Addict dionsiseire's Avatar
    Join Date
    Apr 2005
    Location
    Dublin
    Posts
    334
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Aces mate

    cheers


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •