Query results into an array only storing one result
I'm successfully connecting to a mssql database and getting results, but I'm trying to place them in an array for display on the page.
The following always gets 1 result and nothing more.
I thought arrays are supposed to store multiple results?
<?php
$conn=odbc_connect('*****','******','*****');
if (!$conn)
{exit("Connection Failed: " . $conn);}
$sql="select Name,Id,Group from members";
$rs=odbc_exec($conn,$sql);
if (!$rs)
{exit("Error in SQL");
echo '<div>';
while (odbc_fetch_row($rs))
{
$id=odbc_result($rs,"Id");
$group=odbc_result($rs,"Group");
$name=odbc_result($rs,"Name");
$memberinfo = array("group" => "$group", "Name" => "$name", "Id" => $id);
}
var_dump($memberinfo);
odbc_close($conn);
echo "</div>";
?>What am I doing wrong here?

Replies
using arrays
You're over writing the prior value on each loop through your record set.
Try this instead
$memberinfo[] = array("group" => "$group", "Name" => "$name", "Id" => $id);Which will create an array for each result
$memberinfo[0] first result and so on depending on how many rows returned.
Post new comment