Jump to content


Photo

Help with SQL query and associative array


  • Please log in to reply
2 replies to this topic

#1 indig0blue

indig0blue
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 09 April 2006 - 10:11 PM

I am using a SQL query to pull data that I need for a report. I can get it to print out just fine on screen, but I can't figure out how to get the data into an associative array. I have been playing with this for the past few days and cannot get over the hump on this one.

Can someone please help?

The reason i need to get this data into an associative array is because the data represents a report I need to export into Excel via the xlsStream class.

Any help would be much appreciated. I need to get this done for my boss ASAP.

Thanks. I am desperate.

#2 indig0blue

indig0blue
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 10 April 2006 - 12:51 AM

I was able to get the results to go into an array but now I am only able to get one row of the array in the variable. I need the '$assoc' variable in the code below to hold every row so all the rows will show up in the excel file.

Here is the code i have for this:

$row=0;

while ($row=odbc_fetch_array($sql_result))
{
$ItemNum = $row['ItemNum'];
$Place = $row['Place'];
$QR = 1;
for ($i=0; $i<5; $i++)
{
$assoc = array(array("ItemNum" => $ItemNum, "Place" => $Place, "QR" => $QR));
//echo $assoc;
}
}

Thank you very much in advance.

#3 mistergoomba

mistergoomba
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 10 April 2006 - 01:14 AM

if i'm reading it right, you want to get $row['ItemNum'] to work as opposed to $row[1] which you are getting?! I use MySQL, so the line would be $row=mysql_fetch_assoc($res), but in your case, id guess it would be $row=odbc_fetch_assoc($res)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users