unpack a string

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

    unpack a string

    I have used this function to create a string called $headers:

    function GetHeaders($fil e_name){
    return "<th><a href='".$file_n ame."&order_by= l_e'>L_E</a></th>
    <th><a href='".$file_n ame."&order_by= carnumber'>Carn umber</a></th>
    <th><a href='".$file_n ame."&order_by= location'>Locat ion</a></th>
    <th><a href='".$file_n ame."&order_by= sighting_date_a sc'>Sighting
    Date</a></th>
    <th><a href='".$file_n ame."&order_by= classification' >Code</a></th>
    <th><a href='".$file_n ame."&order_by= railroad'>RR</a></th>
    <th><a href='".$file_n ame."order_by=o rigin'>Origin</a></th>
    <th><a href='".$file_n ame."&order_by= destination'>De stination</a></
    th>
    <th width='15%'><a href='".$file_n ame."'>ETA</a></th>";
    }

    Now I want to unpack the $header array and create two strings,
    called s1 and s2. I want s1 to be field names for excel and s2 to
    be the column names. For example l_e is the field name and L_E is
    capitalized to be the column header in Excel. In other words, I want
    is the two fields after the order_by= without the 'and the </a>.

    How to use unpack?

    s1=unpack($head ers/37, 9, $data)

    I don't know how to use unpack but I have the $header array as the
    string, I counted 37 characters to the word order_by and the word
    order_by= is 9 characters I want to grab that word before the '.
    How do I make use of the unpack function to get what I want?

    tia,
  • Jerry Stuckle

    #2
    Re: unpack a string

    JRough wrote:
    I have used this function to create a string called $headers:
    >
    function GetHeaders($fil e_name){
    return "<th><a href='".$file_n ame."&order_by= l_e'>L_E</a></th>
    <th><a href='".$file_n ame."&order_by= carnumber'>Carn umber</a></th>
    <th><a href='".$file_n ame."&order_by= location'>Locat ion</a></th>
    <th><a href='".$file_n ame."&order_by= sighting_date_a sc'>Sighting
    Date</a></th>
    <th><a href='".$file_n ame."&order_by= classification' >Code</a></th>
    <th><a href='".$file_n ame."&order_by= railroad'>RR</a></th>
    <th><a href='".$file_n ame."order_by=o rigin'>Origin</a></th>
    <th><a href='".$file_n ame."&order_by= destination'>De stination</a></
    th>
    <th width='15%'><a href='".$file_n ame."'>ETA</a></th>";
    }
    >
    Now I want to unpack the $header array and create two strings,
    called s1 and s2. I want s1 to be field names for excel and s2 to
    be the column names. For example l_e is the field name and L_E is
    capitalized to be the column header in Excel. In other words, I want
    is the two fields after the order_by= without the 'and the </a>.
    >
    How to use unpack?
    >
    s1=unpack($head ers/37, 9, $data)
    >
    I don't know how to use unpack but I have the $header array as the
    string, I counted 37 characters to the word order_by and the word
    order_by= is 9 characters I want to grab that word before the '.
    How do I make use of the unpack function to get what I want?
    >
    tia,
    >
    What's wrong with

    $s1 = isset($_GET['order_by']) ? $_GET['order_by'] : '';

    --
    =============== ===
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    jstucklex@attgl obal.net
    =============== ===

    Comment

    • =?UTF-8?B?SXbDoW4gU8OhbmNoZXogT3J0ZWdh?=

      #3
      Re: unpack a string

      JRough wrote:
      I have used this function to create a string called $headers:
      [...]
      Now I want to unpack the $header array and create two strings,
      So, is it a string or an array? Clear your mind.
      How to use unpack?
      You don't want to use unpack(). It's used to get binary data from
      fixed-lenght records, not for this. What you want to do is to *parse* HTML.

      --
      ----------------------------------
      Iván Sánchez Ortega -ivan-algarroba-sanchezortega-punto-es-

      You will gain money by an illegal action.

      Comment

      • JRough

        #4
        Re: unpack a string

        On Sep 9, 2:12 pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
        JRough wrote:
        I have used this function to create a string called $headers:
        >
        function GetHeaders($fil e_name){
          return "<th><a href='".$file_n ame."&order_by= l_e'>L_E</a></th>
                   <th><a href='".$file_n ame."&order_by= carnumber'>Carn umber</a></th>
                   <th><a href='".$file_n ame."&order_by= location'>Locat ion</a></th>
                   <th><a href='".$file_n ame."&order_by= sighting_date_a sc'>Sighting
        Date</a></th>

        How can I tell if it worked or not? I tried adding these 2 lines and
        did not get a value for $s1? The page does work.

        $s1 = isset($_GET['order_by']) ? $_GET['order_by'] : '';
        var_dump $s1;

        it is in the else at the end where if the user wants to see the
        browser page or if he wants to see it in Excel.
        tia,
        Janis

        ---------idle_cars.php-----


        include './includes/config.inc.php' ;
        include $include_path.' dates.inc.php';
        include $include_path." LMS_functions.i nc.php";


        #// ############### ############### ############### ##
        #// Is the user logged in?
        Validate_login( "idle_cars.php? id=".$id);



        $days = 3;
        $TPL_carnumbers = "<table>";

        if(empty($order _by)){
        $order_by = 'sighting_date_ asc';
        }

        # GET CARS FOR GIVEN PARAMETER?
        if(empty($id)){
        $MSG_carlist = "IDLE CARS - NO MOVEMENT IN 3 DAYS";
        $file_name = "idle_cars.php? ";
        switch ($_SESSION["LMS_USER_D ESC"]){
        case 'internal':
        $headers = GetLeaseHeaders ($file_name);
        $result = SELECT_idle_day s($days,CLM_ord er_by($order_by ));
        $lease_row = true;
        break;
        case 'owner':
        $headers = GetLeaseHeaders ($file_name);
        $result = SELECT_idle_day s_owner($days,C LM_order_by($or der_by));
        $lease_row = true;
        break;
        case 'customer':
        $headers = GetHeaders($fil e_name);
        $result = SELECT_idle_day s_customer($day s,CLM_order_by( $order_by));
        $lease_row = false;
        break;
        default:
        $headers = GetLeaseHeaders ($file_name);
        $result = SELECT_idle_day s($days,CLM_ord er_by($order_by ));
        $lease_row = true;
        break;
        }
        }else{
        $MSG_carlist = "IDLE CARS - NO MOVEMENT IN 3 DAYS
        ".GetLeaseCompN ame($id);
        $file_name = "idle_cars.php? id=".$id."&";
        switch ($_SESSION["LMS_USER_D ESC"]){
        case 'internal':
        $headers = GetHeaders($fil e_name);
        $result = SELECT_idle_day s_lease($id,
        $days,CLM_order _by($order_by)) ;
        $lease_row = false;
        break;
        case 'owner':
        $headers = GetHeaders($fil e_name);
        $result = SELECT_idle_day s_lease_owner($ id,
        $days,CLM_order _by($order_by)) ;
        $lease_row = false;
        break;
        default:
        $headers = GetHeaders($fil e_name);
        $result = SELECT_idle_day s_lease($id,
        $days,CLM_order _by($order_by)) ;
        $lease_row = false;
        break;
        }
        }
        $TPL_carnumbers .= $headers;

        if ($_POST['assign']!='Open in Excel'){


        if(mysql_numrow s($result)==0){
        $TPL_carnumbers .= GetNoCarsMsg($t h);
        }else{
        while ($row = mysql_fetch_ass oc($result)){
        $TPL_carnumbers .=MakeSighting( $lease_row,$row );
        }
        }

        $TPL_carnumbers .="</table>";

        include "header.php ";
        include $template_path. "template_carli st.html";
        include "footer.php ";

        }else{
        var_dump($resul t);

        $s1 = isset($_GET['order_by']) ? $_GET['order_by'] : '';

        var_dump($s1);
        #$data.=makexcl ();
        }
        include "footer.php ";

        Comment

        • JRough

          #5
          Re: unpack a string

          On Sep 9, 2:12 pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
          JRough wrote:
          I have used this function to create a string called $headers:
          >
          function GetHeaders($fil e_name){
            return "<th><a href='".$file_n ame."&order_by= l_e'>L_E</a></th>
                     <th><a href='".$file_n ame."&order_by= carnumber'>Carn umber</a></th>
                     <th><a href='".$file_n ame."&order_by= location'>Locat ion</a></th>
                     <th><a href='".$file_n ame."&order_by= sighting_date_a sc'>Sighting
          Date</a></th>
                     <th><a href='".$file_n ame."&order_by= classification' >Code</a></th>
                     <th><a href='".$file_n ame."&order_by= railroad'>RR</a></th>
                     <th><a href='".$file_n ame."order_by=o rigin'>Origin</a></th>
                     <th><a href='".$file_n ame."&order_by= destination'>De stination</a></
          th>
                     <th width='15%'><a href='".$file_n ame."'>ETA</a></th>";
          }
          >
          Now I want to  unpack the $header array and create two  strings,
          called s1 and s2.  I want s1 to be  field names for  excel  ands2 to
          be the column names.  For example l_e is the  field name and L_E is
          capitalized to be the column header in Excel.  In other words, I want
          is the two fields after the order_by= without the 'and the </a>.
          >
          How to use unpack?
          >
          s1=unpack($head ers/37, 9, $data)
          >
          I don't know how to use unpack but I have the $header array as the
          string, I counted 37 characters to the word order_by and the word
          order_by= is 9 characters I want to grab that word before the '.
          How do I make use of the unpack function to get what I want?
          >
          tia,
          >
          What's wrong with
          >
          $s1 = isset($_GET['order_by']) ? $_GET['order_by'] : '';
          >
          --
          =============== ===
          Remove the "x" from my email address
          Jerry Stuckle
          JDS Computer Training Corp.
          jstuck...@attgl obal.net
          =============== ===
          Okay, I tested the variable and I did not get nothing. I hit the else
          for the Excel button and this is the response to a
          print $s1;

          string(0) ""
          which is empty.

          I still need to unpack somehow the string even if I don't use unpack.

          Comment

          • JRough

            #6
            Re: unpack a string

            On Sep 9, 2:40 pm, Iván Sánchez Ortega <ivansanchez-...@rroba-
            escomposlinux.-.punto.-.orgwrote:
            JRough wrote:
            I have used this function to create a string called $headers:
            [...]
            Now I want to  unpack the $header array and create two  strings,
            >
            So, is it a string or an array? Clear your mind.
            >
            How to use unpack?
            >
            You don't want to use unpack(). It's used to get binary data from
            fixed-lenght records, not for this. What you want to do is to *parse* HTML.
            >
            --
            ----------------------------------
            Iván Sánchez Ortega -ivan-algarroba-sanchezortega-punto-es-
            >
            You will gain money by an illegal action.
            I agree with you. Parse is a better word. So I guess I have to use
            string functions then? I'll see if I can and if not
            I'll repost the question.

            thanks

            Comment

            • JRough

              #7
              Re: unpack a string

              On Sep 9, 2:40 pm, Iván Sánchez Ortega <ivansanchez-...@rroba-
              escomposlinux.-.punto.-.orgwrote:
              JRough wrote:
              I have used this function to create a string called $headers:
              [...]
              Now I want to  unpack the $header array and create two  strings,
              >
              So, is it a string or an array? Clear your mind.
              >
              How to use unpack?
              >
              You don't want to use unpack(). It's used to get binary data from
              fixed-lenght records, not for this. What you want to do is to *parse* HTML.
              >
              --
              ----------------------------------
              Iván Sánchez Ortega -ivan-algarroba-sanchezortega-punto-es-
              >
              You will gain money by an illegal action.
              So only numbers can be used with unpack? What do they mean by binary
              data? 1's and 0's? When do you use that? I am just curious.

              Comment

              • =?UTF-8?B?SXbDoW4gU8OhbmNoZXogT3J0ZWdh?=

                #8
                Re: unpack a string

                JRough wrote:
                I agree with you. Parse is a better word. So I guess I have to use
                string functions then?
                No.

                Building strings just to parse them down later in the same program is plain
                stupid. Refactor your code instead.

                --
                ----------------------------------
                Iván Sánchez Ortega -ivan-algarroba-sanchezortega-punto-es-

                Proudly running Debian Linux with 2.6.26-1-amd64 kernel, KDE 3.5.9, and PHP
                5.2.6-2+b1 generating this signature.
                Uptime: 01:26:09 up 19 days, 13:21, 2 users, load average: 0.14, 0.31,
                0.34

                Comment

                • =?UTF-8?B?SXbDoW4gU8OhbmNoZXogT3J0ZWdh?=

                  #9
                  Re: unpack a string

                  JRough wrote:
                  >You don't want to use unpack(). It's used to get binary data from
                  >fixed-lenght records, not for this.
                  >
                  So only numbers can be used with unpack? What do they mean by binary
                  data? 1's and 0's? When do you use that? I am just curious.
                  Have you ever, using C, written a record into a file?

                  --
                  ----------------------------------
                  Iván Sánchez Ortega -ivan-algarroba-sanchezortega-punto-es-

                  Proudly running Debian Linux with 2.6.26-1-amd64 kernel, KDE 3.5.9, and PHP
                  5.2.6-2+b1 generating this signature.
                  Uptime: 01:27:36 up 19 days, 13:23, 2 users, load average: 0.28, 0.31,
                  0.34

                  Comment

                  • JRough

                    #10
                    Re: unpack a string

                    On Sep 9, 2:12 pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
                    JRough wrote:
                    I have used this function to create a string called $headers:
                    >
                    function GetHeaders($fil e_name){
                      return "<th><a href='".$file_n ame."&order_by= l_e'>L_E</a></th>
                               <th><a href='".$file_n ame."&order_by= carnumber'>Carn umber</a></th>
                               <th><a href='".$file_n ame."&order_by= location'>Locat ion</a></th>
                               <th><a href='".$file_n ame."&order_by= sighting_date_a sc'>Sighting
                    Date</a></th>
                               <th><a href='".$file_n ame."&order_by= classification' >Code</a></th>
                               <th><a href='".$file_n ame."&order_by= railroad'>RR</a></th>
                               <th><a href='".$file_n ame."order_by=o rigin'>Origin</a></th>
                               <th><a href='".$file_n ame."&order_by= destination'>De stination</a></
                    th>
                               <th width='15%'><a href='".$file_n ame."'>ETA</a></th>";
                    }
                    >
                    Now I want to  unpack the $header array and create two  strings,
                    called s1 and s2.  I want s1 to be  field names for  excel  ands2 to
                    be the column names.  For example l_e is the  field name and L_E is
                    capitalized to be the column header in Excel.  In other words, I want
                    is the two fields after the order_by= without the 'and the </a>.
                    >
                    How to use unpack?
                    >
                    s1=unpack($head ers/37, 9, $data)
                    >
                    I don't know how to use unpack but I have the $header array as the
                    string, I counted 37 characters to the word order_by and the word
                    order_by= is 9 characters I want to grab that word before the '.
                    How do I make use of the unpack function to get what I want?
                    >
                    tia,
                    >
                    What's wrong with
                    >
                    $s1 = isset($_GET['order_by']) ? $_GET['order_by'] : '';
                    >
                    --
                    =============== ===
                    Remove the "x" from my email address
                    Jerry Stuckle
                    JDS Computer Training Corp.
                    jstuck...@attgl obal.net
                    =============== ===
                    I do wonder why it doesn't work? If the user clicks an anchor then it
                    sorts the rows. You would think the $_GET would pick it up
                    in the url but I suspect the answer to that is the list only prints
                    in the browser but when you hit the else in the code then
                    you aren't in the browser anymore you are formatting the query list
                    for output to excel. Maybe that is the answer.
                    thanks,

                    Comment

                    • JRough

                      #11
                      Re: unpack a string

                      On Sep 9, 2:40 pm, Iván Sánchez Ortega <ivansanchez-...@rroba-
                      escomposlinux.-.punto.-.orgwrote:
                      JRough wrote:
                      I have used this function to create a string called $headers:
                      [...]
                      Now I want to  unpack the $header array and create two  strings,
                      >
                      So, is it a string or an array? Clear your mind.
                      >
                      How to use unpack?
                      >
                      You don't want to use unpack(). It's used to get binary data from
                      fixed-lenght records, not for this. What you want to do is to *parse* HTML.
                      >
                      --
                      ----------------------------------
                      Iván Sánchez Ortega -ivan-algarroba-sanchezortega-punto-es-
                      >
                      You will gain money by an illegal action.
                      Maybe I need regexps?

                      Comment

                      • JRough

                        #12
                        Re: unpack a string

                        On Sep 9, 4:28 pm, Iván Sánchez Ortega <ivansanchez-...@rroba-
                        escomposlinux.-.punto.-.orgwrote:
                        JRough wrote:
                        You don't want to use unpack(). It's used to get binary data from
                        fixed-lenght records, not for this.
                        >
                        So only numbers can be used with unpack?  What do they mean by binary
                        data?  1's and 0's?  When do you use that? I am just curious.
                        >
                        Have you ever, using C, written a record into a file?
                        >
                        --
                        ----------------------------------
                        Iván Sánchez Ortega -ivan-algarroba-sanchezortega-punto-es-
                        >
                        Proudly running Debian Linux with 2.6.26-1-amd64 kernel, KDE 3.5.9, and PHP
                        5.2.6-2+b1 generating this signature.
                        Uptime: 01:27:36 up 19 days, 13:23,  2 users,  load average: 0.28, 0.31,
                        0.34
                        I don't use c for anything. I used c-shell to write a backup
                        script. okay, thanks it is for writing and reading files or records
                        so that could be a stored procedure.

                        I did get more clarity on this string problem. Okay, I have 2
                        functions that are called to display lists on a page that sort the
                        rows depending on the header links clicked. The difference in which
                        function is called depends on which user is logged in. Here is the
                        outputs, the 2nd header row begins with lease numbers:

                        L_E Carnumber Location Sighting Date Code RR Origin
                        Destination ETA

                        LeaseL_E Carnumber Location Sighting Date Code RR Origin
                        Destination ETA

                        All I have to do is "parse" the string so I can output it to excel.
                        Actually what I need to do is put a "\t" between each word and return
                        the string.

                        the $header array has all the anchor tags. I don't need those so I
                        can't use $headers it has to be parsed.

                        thanks,

                        functions:

                        function GetHeaders($fil e_name){
                        return "<th><a href='".$file_n ame."&order_by= l_e'>L_E</a></th>
                        <th><a href='".$file_n ame."&order_by= carnumber'>Carn umber</a></th>
                        <th><a href='".$file_n ame."&order_by= location'>Locat ion</a></th>
                        <th><a href='".$file_n ame."&order_by= sighting_date_a sc'>Sighting
                        Date</a></th>
                        <th><a href='".$file_n ame."&order_by= classification' >Code</a></th>
                        <th><a href='".$file_n ame."&order_by= railroad'>RR</a></th>
                        <th><a href='".$file_n ame."order_by=o rigin'>Origin</a></th>
                        <th><a href='".$file_n ame."&order_by= destination'>De stination</a></
                        th>
                        <th width='15%'><a href='".$file_n ame."'>ETA</a></th>";
                        }

                        function GetLeaseHeaders ($file_name){
                        $lease_header = "<th><a href='".$file_n ame."order_by=l ease'>Lease</
                        a></th>";
                        return $lease_header.G etHeaders($file _name);
                        }

                        Comment

                        • JRough

                          #13
                          Re: unpack a string

                          On Sep 9, 4:27 pm, Iván Sánchez Ortega <ivansanchez-...@rroba-
                          escomposlinux.-.punto.-.orgwrote:
                          JRough wrote:
                          I agree with you.  Parse is a better word.  So I guess I have to use
                          string functions then?
                          >
                          No.
                          >
                          Building strings just to parse them down later in the same program is plain
                          stupid. Refactor your code instead.
                          >
                          --
                          ----------------------------------
                          Iván Sánchez Ortega -ivan-algarroba-sanchezortega-punto-es-
                          >
                          Proudly running Debian Linux with 2.6.26-1-amd64 kernel, KDE 3.5.9, and PHP
                          5.2.6-2+b1 generating this signature.
                          Uptime: 01:26:09 up 19 days, 13:21,  2 users,  load average: 0.14, 0.31,
                          0.34
                          This is an urgent question under a time limit. I built the string to
                          output it to the browser which works. All I need to do now is output
                          it to Excel if the user chooses to and I need the header fields. If
                          you want to see the page code I can enclose it. I don't see how you
                          are proposing to do it a different way than to build the first string.
                          I could really use some help and I don't have time to rewrite anything.

                          Comment

                          • JRough

                            #14
                            Re: unpack a string

                            On Sep 9, 4:27 pm, Iván Sánchez Ortega <ivansanchez-...@rroba-
                            escomposlinux.-.punto.-.orgwrote:
                            JRough wrote:
                            I agree with you.  Parse is a better word.  So I guess I have to use
                            string functions then?
                            >
                            No.
                             load average: 0.14, 0.31,
                            0.34
                            ---code----



                            $days = 3;
                            $TPL_carnumbers = "<table>";

                            if(empty($order _by)){
                            $order_by = 'sighting_date_ asc';
                            }

                            # GET CARS FOR GIVEN PARAMETER?
                            if(empty($id)){
                            $MSG_carlist = "IDLE CARS - NO MOVEMENT IN 3 DAYS";
                            $file_name = "idle_cars.php? ";
                            switch ($_SESSION["LMS_USER_D ESC"]){
                            case 'internal':
                            $headers = GetLeaseHeaders ($file_name);
                            $result = SELECT_idle_day s($days,CLM_ord er_by($order_by ));
                            $lease_row = true;
                            break;
                            case 'owner':
                            $headers = GetLeaseHeaders ($file_name);
                            $result = SELECT_idle_day s_owner($days,C LM_order_by($or der_by));
                            $lease_row = true;
                            break;
                            case 'customer':
                            $headers = GetHeaders($fil e_name);
                            $result = SELECT_idle_day s_customer($day s,CLM_order_by( $order_by));
                            $lease_row = false;
                            break;
                            default:
                            $headers = GetLeaseHeaders ($file_name);
                            $result = SELECT_idle_day s($days,CLM_ord er_by($order_by ));
                            $lease_row = true;
                            break;
                            }
                            }else{
                            $MSG_carlist = "IDLE CARS - NO MOVEMENT IN 3 DAYS
                            ".GetLeaseCompN ame($id);
                            $file_name = "idle_cars.php? id=".$id."&";
                            switch ($_SESSION["LMS_USER_D ESC"]){
                            case 'internal':
                            $headers = GetHeaders($fil e_name);
                            $result = SELECT_idle_day s_lease($id,
                            $days,CLM_order _by($order_by)) ;
                            $lease_row = false;
                            break;
                            case 'owner':
                            $headers = GetHeaders($fil e_name);
                            $result = SELECT_idle_day s_lease_owner($ id,
                            $days,CLM_order _by($order_by)) ;
                            $lease_row = false;
                            break;
                            default:
                            $headers = GetHeaders($fil e_name);
                            $result = SELECT_idle_day s_lease($id,
                            $days,CLM_order _by($order_by)) ;
                            $lease_row = false;
                            break;
                            }
                            }
                            $TPL_carnumbers .= $headers;

                            if ($_POST['assign']!='Open in Excel'){


                            if(mysql_numrow s($result)==0){
                            $TPL_carnumbers .= GetNoCarsMsg($t h);
                            }else{
                            while ($row = mysql_fetch_ass oc($result)){
                            $TPL_carnumbers .=MakeSighting( $lease_row,$row );
                            }
                            }

                            $TPL_carnumbers .="</table>";

                            include "header.php ";
                            include $template_path. "template_carli st.html";
                            include "footer.php ";
                            print $headers;
                            }else{

                            # need code to output header, and data to Excel
                            $s1 = isset($_GET['order_by'])? $_GET['order_by'] : ''; # gives a ' '
                            result

                            }
                            include "footer.php ";

                            function GetHeaders($fil e_name){
                            return "<th><a href='".$file_n ame."&order_by= l_e'>L_E</a></th>
                            <th><a href='".$file_n ame."&order_by= carnumber'>Carn umber</a></th>
                            <th><a href='".$file_n ame."&order_by= location'>Locat ion</a></th>
                            <th><a href='".$file_n ame."&order_by= sighting_date_a sc'>Sighting
                            Date</a></th>
                            <th><a href='".$file_n ame."&order_by= classification' >Code</a></th>
                            <th><a href='".$file_n ame."&order_by= railroad'>RR</a></th>
                            <th><a href='".$file_n ame."order_by=o rigin'>Origin</a></th>
                            <th><a href='".$file_n ame."&order_by= destination'>De stination</a></
                            th>
                            <th width='15%'><a href='".$file_n ame."'>ETA</a></th>";
                            }

                            function GetLeaseHeaders ($file_name){
                            $lease_header = "<th><a href='".$file_n ame."order_by=l ease'>Lease</
                            a></th>";
                            return $lease_header.G etHeaders($file _name);
                            }

                            Comment

                            • Jerry Stuckle

                              #15
                              Re: unpack a string

                              JRough wrote:
                              On Sep 9, 2:12 pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
                              >JRough wrote:
                              >>I have used this function to create a string called $headers:
                              >>function GetHeaders($fil e_name){
                              >> return "<th><a href='".$file_n ame."&order_by= l_e'>L_E</a></th>
                              >> <th><a href='".$file_n ame."&order_by= carnumber'>Carn umber</a></th>
                              >> <th><a href='".$file_n ame."&order_by= location'>Locat ion</a></th>
                              >> <th><a href='".$file_n ame."&order_by= sighting_date_a sc'>Sighting
                              >>Date</a></th>
                              >> <th><a href='".$file_n ame."&order_by= classification' >Code</a></th>
                              >> <th><a href='".$file_n ame."&order_by= railroad'>RR</a></th>
                              >> <th><a href='".$file_n ame."order_by=o rigin'>Origin</a></th>
                              >> <th><a href='".$file_n ame."&order_by= destination'>De stination</a></
                              >>th>
                              >> <th width='15%'><a href='".$file_n ame."'>ETA</a></th>";
                              >>}
                              >>Now I want to unpack the $header array and create two strings,
                              >>called s1 and s2. I want s1 to be field names for excel and s2 to
                              >>be the column names. For example l_e is the field name and L_E is
                              >>capitalized to be the column header in Excel. In other words, I want
                              >>is the two fields after the order_by= without the 'and the </a>.
                              >>How to use unpack?
                              >>s1=unpack($he aders/37, 9, $data)
                              >>I don't know how to use unpack but I have the $header array as the
                              >>string, I counted 37 characters to the word order_by and the word
                              >>order_by= is 9 characters I want to grab that word before the '.
                              >>How do I make use of the unpack function to get what I want?
                              >>tia,
                              >What's wrong with
                              >>
                              >$s1 = isset($_GET['order_by']) ? $_GET['order_by'] : '';
                              >>
                              >--
                              >============== ====
                              >Remove the "x" from my email address
                              >Jerry Stuckle
                              >JDS Computer Training Corp.
                              >jstuck...@attg lobal.net
                              >============== ====
                              >
                              I do wonder why it doesn't work? If the user clicks an anchor then it
                              sorts the rows. You would think the $_GET would pick it up
                              in the url but I suspect the answer to that is the list only prints
                              in the browser but when you hit the else in the code then
                              you aren't in the browser anymore you are formatting the query list
                              for output to excel. Maybe that is the answer.
                              thanks,
                              >
                              None of this is in the browser - it all occurs on the server. And if
                              you are clicking on the link as you indicate, it will be in the $_GET array.

                              Try print_r($_GET); to see what you get.

                              --
                              =============== ===
                              Remove the "x" from my email address
                              Jerry Stuckle
                              JDS Computer Training Corp.
                              jstucklex@attgl obal.net
                              =============== ===

                              Comment

                              Working...