By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,278 Members | 1,357 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,278 IT Pros & Developers. It's quick & easy.

unpack a string

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

function GetHeaders($file_name){
return "<th><a href='".$file_name."&order_by=l_e'>L_E</a></th>
<th><a href='".$file_name."&order_by=carnumber'>Carnumber </a></th>
<th><a href='".$file_name."&order_by=location'>Location</a></th>
<th><a href='".$file_name."&order_by=sighting_date_asc'>S ighting
Date</a></th>
<th><a href='".$file_name."&order_by=classification'>Code </a></th>
<th><a href='".$file_name."&order_by=railroad'>RR</a></th>
<th><a href='".$file_name."order_by=origin'>Origin</a></th>
<th><a href='".$file_name."&order_by=destination'>Destina tion</a></
th>
<th width='15%'><a href='".$file_name."'>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($headers/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,
Sep 9 '08 #1
Share this Question
Share on Google+
17 Replies


P: n/a
JRough wrote:
I have used this function to create a string called $headers:

function GetHeaders($file_name){
return "<th><a href='".$file_name."&order_by=l_e'>L_E</a></th>
<th><a href='".$file_name."&order_by=carnumber'>Carnumber </a></th>
<th><a href='".$file_name."&order_by=location'>Location</a></th>
<th><a href='".$file_name."&order_by=sighting_date_asc'>S ighting
Date</a></th>
<th><a href='".$file_name."&order_by=classification'>Code </a></th>
<th><a href='".$file_name."&order_by=railroad'>RR</a></th>
<th><a href='".$file_name."order_by=origin'>Origin</a></th>
<th><a href='".$file_name."&order_by=destination'>Destina tion</a></
th>
<th width='15%'><a href='".$file_name."'>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($headers/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.
js*******@attglobal.net
==================

Sep 9 '08 #2

P: n/a
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.

Sep 9 '08 #3

P: n/a
On Sep 9, 2:12*pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
JRough wrote:
I have used this function to create a string called $headers:
function GetHeaders($file_name){
* return "<th><a href='".$file_name."&order_by=l_e'>L_E</a></th>
* * * * * *<th><a href='".$file_name."&order_by=carnumber'>Carnumber </a></th>
* * * * * *<th><a href='".$file_name."&order_by=location'>Location</a></th>
* * * * * *<th><a href='".$file_name."&order_by=sighting_date_asc'>S ighting
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.inc.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_DESC"]){
case 'internal':
$headers = GetLeaseHeaders($file_name);
$result = SELECT_idle_days($days,CLM_order_by($order_by));
$lease_row = true;
break;
case 'owner':
$headers = GetLeaseHeaders($file_name);
$result = SELECT_idle_days_owner($days,CLM_order_by($order_b y));
$lease_row = true;
break;
case 'customer':
$headers = GetHeaders($file_name);
$result = SELECT_idle_days_customer($days,CLM_order_by($orde r_by));
$lease_row = false;
break;
default:
$headers = GetLeaseHeaders($file_name);
$result = SELECT_idle_days($days,CLM_order_by($order_by));
$lease_row = true;
break;
}
}else{
$MSG_carlist = "IDLE CARS - NO MOVEMENT IN 3 DAYS
".GetLeaseCompName($id);
$file_name = "idle_cars.php?id=".$id."&";
switch ($_SESSION["LMS_USER_DESC"]){
case 'internal':
$headers = GetHeaders($file_name);
$result = SELECT_idle_days_lease($id,
$days,CLM_order_by($order_by));
$lease_row = false;
break;
case 'owner':
$headers = GetHeaders($file_name);
$result = SELECT_idle_days_lease_owner($id,
$days,CLM_order_by($order_by));
$lease_row = false;
break;
default:
$headers = GetHeaders($file_name);
$result = SELECT_idle_days_lease($id,
$days,CLM_order_by($order_by));
$lease_row = false;
break;
}
}
$TPL_carnumbers.= $headers;

if ($_POST['assign']!='Open in Excel'){
if(mysql_numrows($result)==0){
$TPL_carnumbers.= GetNoCarsMsg($th);
}else{
while ($row = mysql_fetch_assoc($result)){
$TPL_carnumbers.=MakeSighting($lease_row,$row);
}
}

$TPL_carnumbers.="</table>";

include "header.php";
include $template_path."template_carlist.html";
include "footer.php";

}else{
var_dump($result);

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

var_dump($s1);
#$data.=makexcl();
}
include "footer.php";
Sep 9 '08 #4

P: n/a
On Sep 9, 2:12*pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
JRough wrote:
I have used this function to create a string called $headers:
function GetHeaders($file_name){
* return "<th><a href='".$file_name."&order_by=l_e'>L_E</a></th>
* * * * * *<th><a href='".$file_name."&order_by=carnumber'>Carnumber </a></th>
* * * * * *<th><a href='".$file_name."&order_by=location'>Location</a></th>
* * * * * *<th><a href='".$file_name."&order_by=sighting_date_asc'>S ighting
Date</a></th>
* * * * * *<th><a href='".$file_name."&order_by=classification'>Code </a></th>
* * * * * *<th><a href='".$file_name."&order_by=railroad'>RR</a></th>
* * * * * *<th><a href='".$file_name."order_by=origin'>Origin</a></th>
* * * * * *<th><a href='".$file_name."&order_by=destination'>Destina tion</a></
th>
* * * * * *<th width='15%'><a href='".$file_name."'>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($headers/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...@attglobal.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.
Sep 9 '08 #5

P: n/a
On Sep 9, 2:40*pm, Ivn Snchez 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.

--
----------------------------------
Ivn Snchez 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
Sep 9 '08 #6

P: n/a
On Sep 9, 2:40*pm, Ivn Snchez 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.

--
----------------------------------
Ivn Snchez 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.
Sep 9 '08 #7

P: n/a
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

Sep 9 '08 #8

P: n/a
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

Sep 9 '08 #9

P: n/a
On Sep 9, 2:12*pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
JRough wrote:
I have used this function to create a string called $headers:
function GetHeaders($file_name){
* return "<th><a href='".$file_name."&order_by=l_e'>L_E</a></th>
* * * * * *<th><a href='".$file_name."&order_by=carnumber'>Carnumber </a></th>
* * * * * *<th><a href='".$file_name."&order_by=location'>Location</a></th>
* * * * * *<th><a href='".$file_name."&order_by=sighting_date_asc'>S ighting
Date</a></th>
* * * * * *<th><a href='".$file_name."&order_by=classification'>Code </a></th>
* * * * * *<th><a href='".$file_name."&order_by=railroad'>RR</a></th>
* * * * * *<th><a href='".$file_name."order_by=origin'>Origin</a></th>
* * * * * *<th><a href='".$file_name."&order_by=destination'>Destina tion</a></
th>
* * * * * *<th width='15%'><a href='".$file_name."'>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($headers/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...@attglobal.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,
Sep 9 '08 #10

P: n/a
On Sep 9, 2:40*pm, Ivn Snchez 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.

--
----------------------------------
Ivn Snchez Ortega -ivan-algarroba-sanchezortega-punto-es-

You will gain money by an illegal action.
Maybe I need regexps?
Sep 9 '08 #11

P: n/a
On Sep 9, 4:28*pm, Ivn Snchez 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?

--
----------------------------------
Ivn Snchez 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($file_name){
return "<th><a href='".$file_name."&order_by=l_e'>L_E</a></th>
<th><a href='".$file_name."&order_by=carnumber'>Carnumber </a></th>
<th><a href='".$file_name."&order_by=location'>Location</a></th>
<th><a href='".$file_name."&order_by=sighting_date_asc'>S ighting
Date</a></th>
<th><a href='".$file_name."&order_by=classification'>Code </a></th>
<th><a href='".$file_name."&order_by=railroad'>RR</a></th>
<th><a href='".$file_name."order_by=origin'>Origin</a></th>
<th><a href='".$file_name."&order_by=destination'>Destina tion</a></
th>
<th width='15%'><a href='".$file_name."'>ETA</a></th>";
}

function GetLeaseHeaders($file_name){
$lease_header = "<th><a href='".$file_name."order_by=lease'>Lease</
a></th>";
return $lease_header.GetHeaders($file_name);
}
Sep 10 '08 #12

P: n/a
On Sep 9, 4:27*pm, Ivn Snchez 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.

--
----------------------------------
Ivn Snchez 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.
Sep 10 '08 #13

P: n/a
On Sep 9, 4:27*pm, Ivn Snchez 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_DESC"]){
case 'internal':
$headers = GetLeaseHeaders($file_name);
$result = SELECT_idle_days($days,CLM_order_by($order_by));
$lease_row = true;
break;
case 'owner':
$headers = GetLeaseHeaders($file_name);
$result = SELECT_idle_days_owner($days,CLM_order_by($order_b y));
$lease_row = true;
break;
case 'customer':
$headers = GetHeaders($file_name);
$result = SELECT_idle_days_customer($days,CLM_order_by($orde r_by));
$lease_row = false;
break;
default:
$headers = GetLeaseHeaders($file_name);
$result = SELECT_idle_days($days,CLM_order_by($order_by));
$lease_row = true;
break;
}
}else{
$MSG_carlist = "IDLE CARS - NO MOVEMENT IN 3 DAYS
".GetLeaseCompName($id);
$file_name = "idle_cars.php?id=".$id."&";
switch ($_SESSION["LMS_USER_DESC"]){
case 'internal':
$headers = GetHeaders($file_name);
$result = SELECT_idle_days_lease($id,
$days,CLM_order_by($order_by));
$lease_row = false;
break;
case 'owner':
$headers = GetHeaders($file_name);
$result = SELECT_idle_days_lease_owner($id,
$days,CLM_order_by($order_by));
$lease_row = false;
break;
default:
$headers = GetHeaders($file_name);
$result = SELECT_idle_days_lease($id,
$days,CLM_order_by($order_by));
$lease_row = false;
break;
}
}
$TPL_carnumbers.= $headers;

if ($_POST['assign']!='Open in Excel'){
if(mysql_numrows($result)==0){
$TPL_carnumbers.= GetNoCarsMsg($th);
}else{
while ($row = mysql_fetch_assoc($result)){
$TPL_carnumbers.=MakeSighting($lease_row,$row);
}
}

$TPL_carnumbers.="</table>";

include "header.php";
include $template_path."template_carlist.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($file_name){
return "<th><a href='".$file_name."&order_by=l_e'>L_E</a></th>
<th><a href='".$file_name."&order_by=carnumber'>Carnumber </a></th>
<th><a href='".$file_name."&order_by=location'>Location</a></th>
<th><a href='".$file_name."&order_by=sighting_date_asc'>S ighting
Date</a></th>
<th><a href='".$file_name."&order_by=classification'>Code </a></th>
<th><a href='".$file_name."&order_by=railroad'>RR</a></th>
<th><a href='".$file_name."order_by=origin'>Origin</a></th>
<th><a href='".$file_name."&order_by=destination'>Destina tion</a></
th>
<th width='15%'><a href='".$file_name."'>ETA</a></th>";
}

function GetLeaseHeaders($file_name){
$lease_header = "<th><a href='".$file_name."order_by=lease'>Lease</
a></th>";
return $lease_header.GetHeaders($file_name);
}

Sep 10 '08 #14

P: n/a
JRough wrote:
On Sep 9, 2:12 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
>JRough wrote:
>>I have used this function to create a string called $headers:
function GetHeaders($file_name){
return "<th><a href='".$file_name."&order_by=l_e'>L_E</a></th>
<th><a href='".$file_name."&order_by=carnumber'>Carnumber </a></th>
<th><a href='".$file_name."&order_by=location'>Location</a></th>
<th><a href='".$file_name."&order_by=sighting_date_asc'>S ighting
Date</a></th>
<th><a href='".$file_name."&order_by=classification'>Code </a></th>
<th><a href='".$file_name."&order_by=railroad'>RR</a></th>
<th><a href='".$file_name."order_by=origin'>Origin</a></th>
<th><a href='".$file_name."&order_by=destination'>Destina tion</a></
th>
<th width='15%'><a href='".$file_name."'>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($headers/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...@attglobal.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.
js*******@attglobal.net
==================

Sep 10 '08 #15

P: n/a
On Sep 9, 7:54*pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
JRough wrote:
On Sep 9, 2:12 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
JRough wrote:
I have used this function to create a string called $headers:
function GetHeaders($file_name){
* return "<th><a href='".$file_name."&order_by=l_e'>L_E</a></th>
* * * * * *<th><a href='".$file_name."&order_by=carnumber'>Carnumber </a></th>
* * * * * *<th><a href='".$file_name."&order_by=location'>Location</a></th>
* * * * * *<th><a href='".$file_name."&order_by=sighting_date_asc'>S ighting
Date</a></th>
* * * * * *<th><a href='".$file_name."&order_by=classification'>Code </a></th>
* * * * * *<th><a href='".$file_name."&order_by=railroad'>RR</a></th>
* * * * * *<th><a href='".$file_name."order_by=origin'>Origin</a></th>
* * * * * *<th><a href='".$file_name."&order_by=destination'>Destina tion</a></
th>
* * * * * *<th width='15%'><a href='".$file_name."'>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($headers/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...@attglobal.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
Sep 10 '08 #16

P: n/a
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?
Sep 10 '08 #17

P: n/a
JRough wrote:
On Sep 9, 4:27 pm, Ivn Snchez 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.

--
----------------------------------
Ivn Snchez 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.
Sep 11 '08 #18

This discussion thread is closed

Replies have been disabled for this discussion.