excel exporter

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • toffee

    excel exporter

    Hi all,

    i have several php files which each run a different SELECT query and
    displays the data in a table. I would like to create an option to export the
    table to excel and one route i would like to go down is creating a single
    export.php file with an excel header; and basically it would read the sql
    query stored in a session; and just create a spreadsheet from the results.
    the problem is each query yields a different number of columns, so what php
    code would tell it to select all fields for every row rather than specifying
    each field one by one?

    I hope this makes sense to you.

    Kind regards

    T


  • Noodle

    #2
    Re: excel exporter


    toffee wrote:
    Hi all,
    >
    i have several php files which each run a different SELECT query and
    displays the data in a table. I would like to create an option to export the
    table to excel and one route i would like to go down is creating a single
    export.php file with an excel header; and basically it would read the sql
    query stored in a session; and just create a spreadsheet from the results.
    the problem is each query yields a different number of columns, so what php
    code would tell it to select all fields for every row rather than specifying
    each field one by one?
    >
    I hope this makes sense to you.
    >
    Kind regards
    >
    T
    Try outputting your results in a CSV format. Excel can read this quite
    well.

    Comment

    • Colin Fine

      #3
      Re: excel exporter

      toffee wrote:
      Hi all,
      >
      i have several php files which each run a different SELECT query and
      displays the data in a table. I would like to create an option to export the
      table to excel and one route i would like to go down is creating a single
      export.php file with an excel header; and basically it would read the sql
      query stored in a session; and just create a spreadsheet from the results.
      the problem is each query yields a different number of columns, so what php
      code would tell it to select all fields for every row rather than specifying
      each field one by one?
      >
      I hope this makes sense to you.
      >
      Kind regards
      >
      T
      >
      >
      Assuming you're using MySQL,
      mysql_fetch_row returns a row as an enumerated array
      mysql_fetch_arr ay returns an enumerated or associative array
      mysql_fetch_obj ect returns an object.

      In each case, you do not need to know in advance how many fields will be
      returned. And if you use the associative array or the object you can get
      at the names of the fields as well.

      Does this answer your question?

      Colin

      Comment

      • toffee

        #4
        when browser is closed

        Hi,

        I have a site accessible via a login system. I would like to track login and
        logout time for every user. I can get the login time no problem - as every
        time someone logs in, a row is added to a mysql table. The problem happens
        with logout as almost no one uses the logout button; rather they just close
        the browser window.
        My question is therefore - am i able to capture the time the browser is
        closed? all login data is stored in a session; so is there a way to find out
        the time the session got deleted which would mean user has left ?

        Kind regards

        T


        Comment

        • Gordon Burditt

          #5
          Re: when browser is closed

          >I have a site accessible via a login system. I would like to track login and
          >logout time for every user. I can get the login time no problem - as every
          >time someone logs in, a row is added to a mysql table. The problem happens
          >with logout as almost no one uses the logout button; rather they just close
          >the browser window.
          >My question is therefore - am i able to capture the time the browser is
          >closed?
          No.
          >all login data is stored in a session; so is there a way to find out
          >the time the session got deleted which would mean user has left ?
          The session being deleted does NOT mean the user has left. And the
          user may leave WITHOUT closing the browser window (he may type in
          a URL, click on a bookmark, etc.) Unless the user is highly motivated
          to explicitly log out (like the site contains private info or can
          be used to spend real money), the vast majority of logouts are going
          to be by timeout.

          You also don't get to run code when the session data is about to
          be deleted.

          Comment

          • PleegWat

            #6
            Re: when browser is closed

            In article <egjuer$s8$1@ne ws.freedom2surf .net>, toffee says...
            I have a site accessible via a login system. I would like to track login and
            logout time for every user. I can get the login time no problem - as every
            time someone logs in, a row is added to a mysql table. The problem happens
            with logout as almost no one uses the logout button; rather they just close
            the browser window.
            My question is therefore - am i able to capture the time the browser is
            closed? all login data is stored in a session; so is there a way to find out
            the time the session got deleted which would mean user has left ?
            I'd suggest saving the last page call in your table. Each time a page is
            called during one session, update the last page call column to the
            current time.
            --
            PleegWat
            Remove caps to reply

            Comment

            • Dundonald

              #7
              Re: when browser is closed


              Gordon Burditt wrote:
              I have a site accessible via a login system. I would like to track login and
              logout time for every user. I can get the login time no problem - as every
              time someone logs in, a row is added to a mysql table. The problem happens
              with logout as almost no one uses the logout button; rather they just close
              the browser window.
              My question is therefore - am i able to capture the time the browser is
              closed?
              >
              No.
              Not strictly true. The onunload event can be captured within a page and
              by use of a HTTP redirect used to call appropriate code to clean up
              session data etc ... Be warned though as always various browsers don't
              support onunload, but my experience with IE has so far been OK since
              version 4.
              >
              all login data is stored in a session; so is there a way to find out
              the time the session got deleted which would mean user has left ?
              >
              The session being deleted does NOT mean the user has left. And the
              user may leave WITHOUT closing the browser window (he may type in
              a URL, click on a bookmark, etc.) Unless the user is highly motivated
              to explicitly log out (like the site contains private info or can
              be used to spend real money), the vast majority of logouts are going
              to be by timeout.
              The onunload also triggers when a user moves off of your page by typing
              a different URL.
              >
              You also don't get to run code when the session data is about to
              be deleted.

              Comment

              Working...