Jump to content

sql results in to array


keeB

Recommended Posts

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
Link to comment
https://forums.phpfreaks.com/topic/13960-sql-results-in-to-array/
Share on other sites

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

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.