keeB Posted July 7, 2006 Share Posted July 7, 2006 I want to store the results of mysql_fetch_array in another array that my function can return instead of manipulating on the spot..Any ideas on how to do this? I hate arrays.[code] $db->query("select * from users where firstname = '$name' or lastname = '$name'"); while ($info = odbc_fetch_array($db->result)){ //some code here to dynamically create an array }//return dynamically created array here...[/code]Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/13960-sql-results-in-to-array/ Share on other sites More sharing options...
Daniel0 Posted July 7, 2006 Share Posted July 7, 2006 [code]$db->query("select * from users where firstname = '$name' or lastname = '$name'"); while ($info = odbc_fetch_array($db->result)){ $array[] = $info }return $array[/code]I'm not sure what you want, but I think this will store all the results in ONE array. Quote Link to comment https://forums.phpfreaks.com/topic/13960-sql-results-in-to-array/#findComment-54462 Share on other sites More sharing options...
keeB Posted July 7, 2006 Author Share Posted July 7, 2006 I fixed this one just now,Thanks for your help, Danielo.Here's what I came up with...[code] $db = new odbc_database(); $db->query("select * from users where firstname = '$name' or lastname = '$name'"); $result = array(); while ($info = odbc_fetch_array($db->result)){ array_push($result, $info); } return $result;[/code]This returns results like this..[code]Array( [0] => Array ( [UserId] => 571131 [FirstName] => Carson [MiddleName] => [LastName] => Smith [Active] => 1 [Login] => Ca013010 [Login2] => [Password] => -1364301504 [PasswordHint] => [PasswordAnswer] => [ExpDate] => [RenewalDate] => 2005-04-23 05:35:00 [ExpChecked] => 1 [Title] => Engineer II, RF [hasToChangePwd] => 1 [TypeId] => [federalTaxIdString] => [ConsecutiveLoginFailures] => 0 [LastFailedLogin] => 2005-07-11 06:11:12.583 [LastLogin] => 2005-03-24 05:35:25.497 ) [1] => Array ( [UserId] => 994559 [FirstName] => Bill[/code]etc.. etc.. etc..Thanks very much Quote Link to comment https://forums.phpfreaks.com/topic/13960-sql-results-in-to-array/#findComment-54464 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.