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?
| SitePoint Sponsor |


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?



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.


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



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.


Aces mate
cheers
Bookmarks