Jump to content


Photo

sql results in to array


  • Please log in to reply
2 replies to this topic

#1 keeB

keeB
  • Staff Alumni
  • Advanced Member
  • 1,078 posts
  • LocationCalifornia

Posted 07 July 2006 - 04:51 PM

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.

$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...

Thanks in advance

Come visit my site to see my latest projects
http://nick.stinemates.org/wordpress/


#2 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 07 July 2006 - 05:16 PM

$db->query("select * from users where firstname = '$name' or lastname = '$name'");
 
	 while ($info = odbc_fetch_array($db->result)){
           $array[] = $info
	 }
return $array

I'm not sure what you want, but I think this will store all the results in ONE array.

#3 keeB

keeB
  • Staff Alumni
  • Advanced Member
  • 1,078 posts
  • LocationCalifornia

Posted 07 July 2006 - 05:18 PM

I fixed this one just now,

Thanks for your help, Danielo.

Here's what I came up with...

 $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;

This returns results like this..

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

etc.. etc.. etc..

Thanks very much

Come visit my site to see my latest projects
http://nick.stinemates.org/wordpress/





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users