Jump to content

Archived

This topic is now archived and is closed to further replies.

indig0blue

Help with SQL query and associative array

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites

×

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.