PHP 8.5.0 Beta 1 available for testing

Voting

: max(three, seven)?
(Example: nine)

The Note You're Voting On

Anonymous
24 years ago
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

<< Back to user notes page

To Top