Whats a simple method of dynamically extracting each row of a SELECT result set into a two dimensional array, using the row number as the index, and the column numbers or names as the 2nd dimension.

echo $table[0]['user'];
echo $table[1]['user'];

So the above would return the contents of the 'user' column from the first and second row respectively of the result set.

I know there are some great classes (ie. ADOdb and ezSQL) that get this and more done, but I need to minimize my code as well as learn the concept.

The current project I'm using this for utilizes Unified ODBC functions to interface with an Access database and I'm wondering where I should go after executing the SELECT query, which should return several rows.

This has been bugging me for quite a while and I just can't seem to grasp how its done. Any help would be great.

    Thank you nemonoman.

    I've looked at the Unified ODBC functions and while the documentation says there is a corresponding odbc function to mysql_fetch_array, the user notes reveal that this function (as well as odbc_fetch_object) are turned off in the source code as well as the builds by default. The user notes also have several homebrewn functions to replace odbc_fetch_array, but I haven't been able to get them to work properly.

    function odbc_fetch_array($result, $rownumber=-1) {
     if (PHP_VERSION > "4.1") {
       if ($rownumber < 0) {
         odbc_fetch_into($result, &$rs);
       } else {
         odbc_fetch_into($result, &$rs, $rownumber);
       }
     } else {
       odbc_fetch_into($result, $rownumber, &$rs);
     }
     foreach ($rs as $key => $value) {
       $rs_assoc[odbc_field_name($result, $key+1)] = $value;
     }
     return $rs_assoc;
    }
    
    function odbc_fetch_resultset($resID)
    {
    /* Return all the rows returned by a query in an array.
    
    */
      $resultSet=array();
    // Assign the field names to $resultSet['fieldNames']
      $fCount = odbc_num_fields($resID); 
      for ($i=1; $i<= $fCount; $i++){
         $fNames[$i] = odbc_field_name($resID, $i); 
      }
      $resultSet['fieldNames']=$fNames;
    // Assign the records
      for ($i=1; odbc_fetch_row($resID,$i); $i++){
         $record=array();
         for ($j = 1; $j <= $fCount; $j++){
            $fName = odbc_field_name($resID, $j); 
            $record[$fName]=odbc_result($resID, $j);
         }
         $resultSet[$i]=$record;
      }
    
    
      return ($resultSet);
    }
    
    

    Above are two of the functions, copied from http://www.php.net/manual/en/function.odbc-fetch-array.php

    How would I be able to construct a working function, or make use of one of the two above functions to achieve the proper results?

      Sorry, asleep at the switch. Totally missed that part about ODBC.

        Write a Reply...