Help with SQL query and associative array

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • geoffcastro@gmail.com

    Help with SQL query and associative array

    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.

  • Erwin Moller

    #2
    Re: Help with SQL query and associative array

    geoffcastro@gma il.com wrote:
    [color=blue]
    > 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.[/color]

    Which database do you use?

    Or do you use an abstractionlaye r maybe?

    The right answer depends on your circumstances.
    eg:
    If you use ADODB, try:
    $RS = $conn->Execute($someS QL)->getArray();
    to make the $RS an assoc array.
    (I always do this because it makes the use of the $RS so much more
    intuitive.)

    If you use ADODB be sure you set the connection-object first in assoc mode,
    with something like:
    $conn->SetFetchMode(A DODB_FETCH_ASSO C);


    From Postgresql:
    use pg_fetch_assoc( )

    etc.

    So just look up the corresponding command for you database at www.php.net.

    Regards,
    Erwin Moller

    Comment

    Working...