Jump to content

ODBC Query Problem - Undefined index


will35010

Recommended Posts

I have this code:

$sql = "SELECT adpat, adptnm, addate, adtime, adddsc, disdt, distm, drname, adptyp, ptprvtyp FROM hma711.zadpatnmf 
JOIN hma711.addocrmf on adamdr = drno WHERE addate BETWEEN '20111115' AND '20111115' AND adpat BETWEEN '2000000' AND '2999999'";

$execute = odbc_exec($conn, $sql);

$num = odbc_num_rows($execute);
echo $num;

while($row = odbc_fetch_array($execute)){
    echo $row['adpat'];
} 

It gets an error on this line: echo $row['adpat'];

 

The error is Notice: Undefined index: adpat in C:\xampp\htdocs\erboard\test.php on line 29

 

The query works directly on the AS400 I'm pulling from and the $num is being populated with the correct number of records.

 

This is the first time I have ever used php with odbc so I'm not sure what I'm missing. Any help would be greatly appreciated. Thanks!

Link to comment
https://forums.phpfreaks.com/topic/251213-odbc-query-problem-undefined-index/
Share on other sites

odbc_fetch_array() may not (ever?) include column names in the array. Assume it's just a straight list with numeric keys.

 

You could fairly easily build your own function to return an associate array by using odbc_field_name.

odbc_fetch_array() may not (ever?) include column names in the array. Assume it's just a straight list with numeric keys.

 

You could fairly easily build your own function to return an associate array by using odbc_field_name.

 

I tried this without any luck

for($i=1;$row=odbc_fetch_row($execute,$i);$i++) {    
    echo $row[0];
}

I have it returning the results with this:

$sql = "SELECT adpat, adptnm, addate, adtime, adddsc, disdt, distm, drname, adptyp, ptprvtyp FROM hma711.zadpatnmf 
JOIN hma711.addocrmf on adamdr = drno WHERE addate BETWEEN '20111115' AND '20111115' AND adpat BETWEEN '2000000' AND '2999999'";

$execute = odbc_exec($conn, $sql);

$count = odbc_num_rows($execute);
echo $count."</br>";
$i = 1;
while($i<=$count)
  {
  $pat_num = odbc_result($execute, "adpat");
  echo $pat_num;
  $pat_nam = odbc_result($execute, "adptnm");
  echo $pat_nam."</br>";
  $i++;
  }

 

But it repeatedly echos on the first row of data for all records returned.

I got it working with this:

$i = 1;
while($row = odbc_fetch_array($execute, $i)){
    $pat_num = odbc_result($execute, "adpat");
    echo $pat_num;
    $pat_nam = odbc_result($execute, "adptnm");
    echo $pat_nam."</br>";
    $i++;
}

 

AS400 DB2 is no fun compared to mysql.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.