unpack a string

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

    #16
    Re: unpack a string

    On Sep 9, 7:54 pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
    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($hea ders/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,
    >
    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.
    >
    I tried print_r I got a parse error on that line:

    Parse error: syntax error, unexpected T_VARIABLE in /home/allrail/
    public_html/idle_cars.php on line 101

    Does that mean it is working because there is soemthing in the string?
    here is that section of code:

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

    print_r $s1 ;

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

    I don't think I have a typo in it., tnx,
    Janis

    Comment

    • Captain Paralytic

      #17
      Re: unpack a string

      On 10 Sep, 03:08, JRough <jlro...@yahoo. comwrote:
      This is an urgent question under a time limit.  I built the string to
      output it to the browser which works.  
      Have you thought of employing a programmer?

      Comment

      • sheldonlg

        #18
        Re: unpack a string

        JRough wrote:
        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
        Have you googled to see what is out there? I did about a year ago and
        found a nice class to do the job that works like a charm. It included
        headers for the columns. The only drawback I found was that I could
        only output one array. I don't have the pointer to where on the net it
        is (I copy my own copy now. Use keywords like php export to excel).
        You will just have to do your own homework on this one.

        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

        Working...