Mr_Pancakes Posted September 15, 2006 Share Posted September 15, 2006 i've written a function to help me store the results of a sql query into a multidimensional array. the function seems to be working ok, but i was wondering if there is a better way to do this from an OBDC referenced database? did i miss anything?[code]function execute_sql($cmd){ $connection = db_connect(); $rs = odbc_exec($connection,$cmd); if (!$rs){ exit("Error in SQL"); } if (odbc_fetch_row($rs)){ $rows = odbc_num_rows($rs); if ($rows <= 1){ $answer[] = odbc_fetch_array($rs, 1); } else { for ($k = 0; $k <= $rows; $k++){ $answer[] = odbc_fetch_array($rs, $k); } } } odbc_close($connection); if (!empty($answer)) { return $answer; } else { return false; }}[/code]if we're querying for say: fname, lname; this returns a result in the form of:[code]print $answer[0]['fname'] . $answer[0]['lname']; // John Doeprint $answer[1]['fname'] . $answer[1]['lname']; // Jane Doughprint $answer[2]['fname'] . $answer[2]['lname']; // Mister Tea// ...etc.[/code]any ideas what im missing?-steve Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.