note 11866 modified in function.odbc-field-name by felipe
| From: | felipe@php.net | Date: | Tue, 22 Jul 2008 18:58:21 +0000 |
| Subject: | note 11866 modified in function.odbc-field-name by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-142534@lists.php.net to get a copy of this message | ||
Wow, I finally have something to contribute.
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?
<?php
$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
--was--
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
http://php.net/manual/en/function.odbc-field-name.php