will35010 Posted November 15, 2011 Share Posted November 15, 2011 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 More sharing options...
PFMaBiSmAd Posted November 15, 2011 Share Posted November 15, 2011 See what var_dump($row); shows? Link to comment https://forums.phpfreaks.com/topic/251213-odbc-query-problem-undefined-index/#findComment-1288474 Share on other sites More sharing options...
requinix Posted November 15, 2011 Share Posted November 15, 2011 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. Link to comment https://forums.phpfreaks.com/topic/251213-odbc-query-problem-undefined-index/#findComment-1288477 Share on other sites More sharing options...
will35010 Posted November 15, 2011 Author Share Posted November 15, 2011 See what var_dump($row); shows? It returns false like it isn't set. bool(false) Link to comment https://forums.phpfreaks.com/topic/251213-odbc-query-problem-undefined-index/#findComment-1288522 Share on other sites More sharing options...
will35010 Posted November 15, 2011 Author Share Posted November 15, 2011 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]; } Link to comment https://forums.phpfreaks.com/topic/251213-odbc-query-problem-undefined-index/#findComment-1288524 Share on other sites More sharing options...
will35010 Posted November 16, 2011 Author Share Posted November 16, 2011 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. Link to comment https://forums.phpfreaks.com/topic/251213-odbc-query-problem-undefined-index/#findComment-1288532 Share on other sites More sharing options...
will35010 Posted November 16, 2011 Author Share Posted November 16, 2011 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. Link to comment https://forums.phpfreaks.com/topic/251213-odbc-query-problem-undefined-index/#findComment-1288538 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.