![]() |
mysqli: how do i get a list of fields
Is there a way to grab all field names and display them ?
this is what i used to do... Code:
mysql_field_name( $result ,$i); |
You use [mysqli_]fetch_field_direct method. It returns an object and two of the properties are name and orgname.
|
I did try that one, but not understanding how to get the field names.
Code:
$result = db_query($mysqli, $query); $columns = $result->field_count; |
ok i think i have it?
Code:
echo($result->fetch_field_direct($i)->name); |
Yep that should work in the newer versions of PHP.
It won't work in older (and I'm talking like 5.3 here as older, but I'm not 100% sure when it was implemented). The reason is that PHP wasn't designed until very recently to allow dereferencing of the return of a function / method call, only on assigned zval's themselves. So this wouldn't work in older versions. The work around is very easy, which I'd suggest doing at least for the time being anyway: PHP Code:
MySQLi also has the fetch_fields method on the mysqli_result object which returns an array of objects representing each fields. Its the same as the fetch_field_direct except the direct asks which field you want. |
ok i shall try that for now, thanks
|
| All times are GMT +1. The time now is 10:26 PM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.