indig0blue Posted April 9, 2006 Share Posted April 9, 2006 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. Link to comment https://forums.phpfreaks.com/topic/6977-help-with-sql-query-and-associative-array/ Share on other sites More sharing options...
indig0blue Posted April 10, 2006 Author Share Posted April 10, 2006 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. Link to comment https://forums.phpfreaks.com/topic/6977-help-with-sql-query-and-associative-array/#findComment-25367 Share on other sites More sharing options...
mistergoomba Posted April 10, 2006 Share Posted April 10, 2006 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) Link to comment https://forums.phpfreaks.com/topic/6977-help-with-sql-query-and-associative-array/#findComment-25372 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.