note 11865 deleted from function.odbc-field-name by didou
| From: | didou@php.net | Date: | Fri, 09 May 2003 12:56:59 +0000 |
| Subject: | note 11865 deleted from function.odbc-field-name by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-47738@lists.php.net to get a copy of this message | ||
Wow, I finally have something to contribute. :><br><br>
If you, like me, have been seeking a way to name and fill your variables with the appropriate names
an values, rather than naming every variable and using odbc_result($result, 1), odbc_result($result,
2), etc...Then this little loop is for you! It would probably be nice to use as function, but
I'm sure you can do that on your own, eh?<br><br>
<?
$query = "SELECT * FROM TableName";
$result = odbc_exec($conn, $query) or die('Select failed!');
$i = 0;
$fCount = odbc_num_fields($result);
while (odbc_fetch_row($result))
{
while ($i < $fCount)
{
$i++;
$fName = odbc_field_name($result, $i);
$job[$fName] = odbc_result($result, $i);
}
$i=0;
}
?>
This should be pretty simple code to follow, you can address your variables at any time later using
the column names from your table. For now I am addressing them with their real values and using
this simply to avoid having to type out all the variable names in the top of my code. Have fun.
Jason/ArtHacker.com