473,399 Members | 3,656 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

unpack a string

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
17 2273
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
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
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
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
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
Sep 9 '08 #6
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.
Sep 9 '08 #7
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
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
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
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?
Sep 9 '08 #11
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($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
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.
Sep 10 '08 #13
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_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
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
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
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
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.
Sep 11 '08 #18

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Geoffrey | last post by:
Hope someone can help. I am trying to read data from a file binary file and then unpack the data into python variables. Some of the data is store like this; xbuffer:...
3
by: Andrew Robert | last post by:
Hey everyone, Maybe you can see something I don't. I need to convert a working piece of perl code to python. The perl code is: sub ParseTrig {
0
by: Gary Herron | last post by:
Marlin Rowley wrote: Numpy can do this for you. First, do you really mean the array to contain lists of one string each? If so: kludge here array(, dtype='|S1') array(, ,
19
by: JRough | last post by:
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='"....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.