can't redirect to Excel

This is a discussion on can't redirect to Excel within the PHP Language forums, part of the PHP Programming Forums category; I have tried this 4 2 weeks and I need some help. There are 3 other pages referenced on this ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 07-19-2008
JRough
 
Posts: n/a
Default can't redirect to Excel

I have tried this 4 2 weeks and I need some help. There are 3 other
pages referenced on this page but I'm going to start with this page
in case I missed something. It is called current_sightings.php. All
I want to do is redirect to Excel in the case of the External user.
The first if statement creates a form. The elseif redirects the
external user to only his own listings. I want the results for the
Internal user query SELECT_sightings_leasecars.() to go to my
current_sightingsXL.php page. Where/How would I put the redirect? I
think it should be after the switch for external users. The
getTableHeaders() function is the string that gets passed. All the
pages work except I can't redirect the output to Excel.

Something like this:


if($_POST['assign']=='Open in Excel')){
Header("Location:
current_sightingsXL.php?param=".$_Post['id']."&lease_id=".$id);}

But I don't know where to put it. I could give you the
current_sightingsXL.php page if you need it but right now it isn't
redirecting anyway and I could test it if I got it to redirect.



tia,

<?




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("current_sightings.php");

if(empty($id)&&($_SESSION["LMS_USER_DESC"]=='internal')){
# THIS IS id INSTEAD OF lease_id B/C ONE DAY WE MIGHT HAVE CUSTOMER
SUB GROUPS OR MANAGED CARS
$destroyed = GetDestroyed_lease_id();
$result = SELECT_leasesCLM();
$TPL_ids = "<SELECT name='id' class=box size=8>\n";
$trbg = "";

while($row = mysqBul_fetch_assoc($result)){
$id = $row['lease_id'];
$lnum = $row['lease_num'];
$comp = $row['comp_name'];

$trbg = GetTRBG($trbg);

$TPL_ids.=" <OPTION VALUE='".$id;
$TPL_ids.="' ".$trbg.">".$lnum." - ".$comp."</OPTION>\n";
}

$TPL_ids.="</SELECT>\n";
include "header.php";
include $template_path."current_sightings_php.html";


}elseif($_POST['redirect']&&$_POST['redirect']!=$_SERVER['PHP_SELF']){
Header("Location: ".$_POST['redirect'].".php?id=".$_POST['id']);
exit;
/*
}elseif ($_POST['assign']=='Open in Excel'){
Header("Location: current_sightingsXL.php?param=".$_Post['id']."&id=".
$_id);
exit;*/

}else{

# DETERMINE PAGE ACCORDING TO USER TYPE
switch ($_SESSION["LMS_USER_DESC"]){
case "customer":
$id = $_SESSION["LMS_LOGGED_IN"];
$MSG_carlist = "CURRENT SIGHTINGS";
$result =
SELECT_sightings_customercars($id,CLM_order_by($or der_by));
break;
case "internal":
$MSG_carlist = "CURRENT SIGHTINGS FOR ".SELECT_lease_num($id)."
".SELECT_comp_name($id);
$result =
SELECT_sightings_leasecars($id,CLM_order_by($order _by));
break;
#case "internal_ltd":
# break;
}
$TPL_carnumbers = GetTableHeaders($id);
while ($row = mysql_fetch_assoc($result)){
$TPL_carnumbers.=MakeSighting($row);
}

$TPL_carnumbers.="</table>";

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

}


include "footer.php";
######################################
##
## FUNCTIONS
##
######################################

function GetTableHeaders($id){
return "<table>
<th><a href='current_sightings.php?id=".
$id."&order_by=l_e'>L_E</a></th>
<th><a href='current_sightings.php?id=".$id."&'>Carnumber </a></
th>
<th>Type</th>
<th><a href='current_sightings.php?id=".
$id."&order_by=location'>Location</a></th>
<th><a href='current_sightings.php?id=".
$id."&order_by=sighting_date'>Sighting Date</a></th>
<th><a href='current_sightings.php?id=".
$id."&order_by=classification'>Code</a></th>
<th><a href='current_sightings.php?id=".
$id."&order_by=railroad'>RR</a></th>
<th><a href='current_sightings.php?id=".
$id."&order_by=origin'>Origin</a></th>
<th><a href='current_sightings.php?id=".
$id."&order_by=destination'>Destination</a></th>
<th><a href='current_sightings.php?id=".$id."&order_by=et a'>ETA</
a></th>";
}

function GetCars($id,$type,$order_by){
switch($type){
case 'lease':
return SELECT_sightings_leasecars($id,$order_by);
break;
default:
return SELECT_sightings_leasecars($id,$order_by);
break;
}
}

function MakeSighting($row){
$mark = $row['car_mark'];
$num = $row['car_number'];
$l_e = $row['l_e'];
$carnumber = MakeCarnumber($mark,$num);
$location_city = $row['location_city'];
$location_state = $row['location_state'];
$sighting_date = $row['sighting_date'];
$classification = $row['classification'];
$railroad = $row['railroad'];
$origin_city = $row['origin_city'];
$origin_state = $row['origin_state'];
$destination_city = $row['destination_city'];
$destination_state = $row['destination_state'];
$eta = $row['eta'];
if($l_e=='L'){
$trbg = "class='trbg'";
}else{
$trbg = "";
}
return "<tr ".$trbg.">
<td align='center'>".$l_e."</td>
<td><a href='clm_history.php?mark=".$mark."&num=".$num."' >".
$carnumber."</a></td>
<td align='center'>".GetMechanicalDesignationCarnumber ($mark,
$num)."</td>
<td>".MakeCity($location_city,$location_state)." </td>
<td>".CLM_dateFormat($sighting_date)."</td>
<td>".$classification."</td>
<td>".$railroad."</td>
<td>".MakeCity($origin_city,$origin_state)."</td>
<td>".MakeCity($destination_city,$destination_stat e)."</td>
<td>".CLM_dateFormat($eta)."</td>
</tr>";
}

################################
##
## QUERIES
##
################################
function SELECT_leasesCLM(){
$query = "SELECT DISTINCT l.lease_id, m.lease_num, co.comp_name
FROM INTERNAL_LEASES l, INTERNAL_MASTER_LEASE m, INTERNAL_COMPANY
co,
INTERNAL_CAR_LEASE cl, INTERNAL_REMARK r, INTERNAL_CLM c
WHERE co.comp_id = m.comp_id
AND m.master_lease_id = l.master_lease_id
AND l.lease_id = cl.lease_id
AND cl.end_date IS NULL
AND cl.remark_id = r.remark_id
AND r.car_mark = c.car_mark
AND r.car_number = c.car_number";
$result = mysql_query($query);
if(!$result){
MySQLError($query);
exit;
}
return $result;
}

function SELECT_lease_num($lease_id){
$query = "SELECT m.lease_num
FROM INTERNAL_MASTER_LEASE m, INTERNAL_LEASES l
WHERE l.lease_id =".$lease_id."
AND l.master_lease_id = m.master_lease_id";
$result = mysql_query($query);
if(!$result){
MySQLError($query);
exit;
}
$row = mysql_fetch_row($result);
return $row[0];
}

function SELECT_comp_name($lease_id){
$query = "SELECT comp_name
FROM INTERNAL_LEASES l, INTERNAL_MASTER_LEASE m, INTERNAL_COMPANY
c
WHERE l.lease_id = ".$lease_id."
AND l.master_lease_id = m.master_lease_id
AND m.comp_id = c.comp_id";
$result = mysql_query($query);
if(!$result){
MySQLError($query);
exit;
}
$row = mysql_fetch_row($result);
return $row[0];
}

function SELECT_sightings_customercars($id,$order_by){
$query = "SELECT c.l_e,
c.car_mark, c.car_number,
c.location_city, c.location_state,
c.sighting_date,
e.classification,
c.railroad,
s.city as origin_city,
s.state as origin_state,
c.destination_city, c.destination_state,
t.eta
FROM INTERNAL_CUSTOMER_USERS cu, INTERNAL_MASTER_LEASE m,
INTERNAL_LEASES l,
INTERNAL_REMARK r, INTERNAL_CAR_LEASE cl,
clm_lastsighting_view v1, clm_crossreference_view v2,
INTERNAL_CODES e, INTERNAL_CLM c
LEFT JOIN (INTERNAL_TRIPS t, INTERNAL_SPLC s)
ON (c.trip_id = t.trip_id
AND t.origin_splc_id = s.splc_id)
WHERE cu.id = ".$id."
AND cu.comp_id = m.comp_id
AND m.master_lease_id = l.master_lease_id
AND l.lease_id = cl.lease_id
AND cl.end_date IS NULL
AND cl.remark_id = r.remark_id
AND r.car_mark = c.car_mark
AND c.car_mark = v1.car_mark
AND v1.car_mark = v2.car_mark
AND r.car_number = c.car_number
AND c.car_number = v1.car_number
AND v1.car_number = v2.car_number
AND c.sighting_date = v1.sighting_date
AND c.sighting_code = v2.code
AND c.sighting_code = e.code
ORDER BY ".$order_by;
$result = mysql_query($query);
if(!$result){
MySQLError($query);
exit;
}
return $result;
}

function SELECT_sightings_leasecars($lease_id,$order_by){
$query = "SELECT c.l_e,
c.car_mark, c.car_number,
c.location_city, c.location_state,
c.sighting_date,
e.classification,
c.railroad,
s.city as origin_city,
s.state as origin_state,
c.destination_city, c.destination_state,
t.eta
FROM INTERNAL_REMARK r, INTERNAL_CAR_LEASE cl,
clm_lastsighting_view v1,
clm_crossreference_view v2, INTERNAL_CODES e, INTERNAL_CLM c
LEFT JOIN (INTERNAL_TRIPS t, INTERNAL_SPLC s)
ON (c.trip_id = t.trip_id
AND t.origin_splc_id = s.splc_id)
WHERE cl.lease_id = ".$lease_id."
AND cl.end_date IS NULL
AND cl.remark_id = r.remark_id
AND r.car_mark = c.car_mark
AND c.car_mark = v1.car_mark
AND v1.car_mark = v2.car_mark
AND r.car_number = c.car_number
AND c.car_number = v1.car_number
AND v1.car_number = v2.car_number
AND c.sighting_date = v1.sighting_date
AND c.sighting_code = v2.code
AND c.sighting_code = e.code
ORDER BY ".$order_by;
$result = mysql_query($query);
if(!$result){
MySQLError($query);
exit;
}
return $result;
}

?>
Reply With Quote
  #2 (permalink)  
Old 07-19-2008
Paul Lautman
 
Posts: n/a
Default Re: can't redirect to Excel

JRough wrote:
>I have tried this 4 2 weeks and I need some help. There are 3 other
> pages referenced on this page but I'm going to start with this page
> in case I missed something. It is called current_sightings.php. All
> I want to do is redirect to Excel in the case of the External user.
> The first if statement creates a form. The elseif redirects the
> external user to only his own listings. I want the results for the
> Internal user query SELECT_sightings_leasecars.() to go to my
> current_sightingsXL.php page. Where/How would I put the redirect? I
> think it should be after the switch for external users. The
> getTableHeaders() function is the string that gets passed. All the
> pages work except I can't redirect the output to Excel.


What do you mean by "redirect the output to Excel"??? Excel isn't a
location, it's a spreadsheet program that some (but not all users) will have
on their machine.

BTW, Location: is supposed to take a fully qualified URL.


Reply With Quote
  #3 (permalink)  
Old 07-19-2008
Jeff
 
Posts: n/a
Default Re: can't redirect to Excel

Paul Lautman wrote:
> JRough wrote:
>> I have tried this 4 2 weeks and I need some help. There are 3 other
>> pages referenced on this page but I'm going to start with this page
>> in case I missed something. It is called current_sightings.php. All
>> I want to do is redirect to Excel in the case of the External user.
>> The first if statement creates a form. The elseif redirects the
>> external user to only his own listings. I want the results for the
>> Internal user query SELECT_sightings_leasecars.() to go to my
>> current_sightingsXL.php page. Where/How would I put the redirect? I
>> think it should be after the switch for external users. The
>> getTableHeaders() function is the string that gets passed. All the
>> pages work except I can't redirect the output to Excel.

>
> What do you mean by "redirect the output to Excel"??? Excel isn't a
> location, it's a spreadsheet program that some (but not all users) will have
> on their machine.
>
> BTW, Location: is supposed to take a fully qualified URL.


What is a fully qualified URL? A Google search has left me more confused
than before.

Now, this is of course, fully qualified:

header("Location: http://www.example.com/");

and this presumably isn't:

header("Location: www.example.com/");

But what about this?:

header("Location: /new_page_in_html_root.html");

or:

header("Location: page_in_same_directory.html");

Now, as far as what the op wants, which isn't clear, you can use a
header statement (and have it work) as long as there the is no html
outputted (either echoed or embedded) before the header.


Jeff
>
>

Reply With Quote
  #4 (permalink)  
Old 07-19-2008
Paul Lautman
 
Posts: n/a
Default Re: can't redirect to Excel

Jeff wrote:
> Paul Lautman wrote:
>> JRough wrote:
>>> I have tried this 4 2 weeks and I need some help. There are 3 other
>>> pages referenced on this page but I'm going to start with this page
>>> in case I missed something. It is called current_sightings.php. All I
>>> want to do is redirect to Excel in the case of the External
>>> user. The first if statement creates a form. The elseif
>>> redirects the external user to only his own listings. I want the
>>> results for the Internal user query SELECT_sightings_leasecars.()
>>> to go to my current_sightingsXL.php page. Where/How would I put
>>> the redirect? I think it should be after the switch for external
>>> users. The getTableHeaders() function is the string that gets
>>> passed. All the pages work except I can't redirect the output to
>>> Excel.

>>
>> What do you mean by "redirect the output to Excel"??? Excel isn't a
>> location, it's a spreadsheet program that some (but not all users)
>> will have on their machine.
>>
>> BTW, Location: is supposed to take a fully qualified URL.

>
> What is a fully qualified URL? A Google search has left me more
> confused than before.
>
> Now, this is of course, fully qualified:
>
> header("Location: http://www.example.com/");
>
> and this presumably isn't:
>
> header("Location: www.example.com/");
>
> But what about this?:
>
> header("Location: /new_page_in_html_root.html");
>
> or:
>
> header("Location: page_in_same_directory.html");

From the php manual:
HTTP/1.1 requires an absolute URI as argument to Location: including the
scheme, hostname and absolute path, but some clients accept relative URIs.
You can usually use $_SERVER['HTTP_HOST'], $_SERVER['PHP_SELF'] and
dirname() to make an absolute URI from a relative one yourself:
<?php
header("Location: http://" . $_SERVER['HTTP_HOST']
. rtrim(dirname($_SERVER['PHP_SELF']), '/\\')
. "/" . $relative_url);
?>

> Now, as far as what the op wants, which isn't clear, you can use a
> header statement (and have it work) as long as there the is no html
> outputted (either echoed or embedded) before the header.

I have absolutely no idea what the OP wants since what he described doesn't
exist.


Reply With Quote
  #5 (permalink)  
Old 07-19-2008
John Dunlop
 
Posts: n/a
Default Re: can't redirect to Excel

Jeff:

> What is a fully qualified URL?


One that is absolute, not relative, I would presume.

> A Google search has left me more confused than before.


Likely bitten by the terminology: "fully qualified" collocates with
domain names; "absolute" is a technical term to describe URLs.

> Now, this is of course, fully qualified:
>
> header("Location:http://www.example.com/");
>
> and this presumably isn't:
>
> header("Location:www.example.com/");


Indeed.

> But what about this?:
>
> header("Location: /new_page_in_html_root.html");


Termed an "absolute-path reference". Not an absolute URL, so violates
RFC 2616.

> or:
>
> header("Location: page_in_same_directory.html");


Termed a "relative-path reference". Again, not an absolute URL.

--
Jock
Reply With Quote
  #6 (permalink)  
Old 07-19-2008
JRough
 
Posts: n/a
Default Re: can't redirect to Excel

On Jul 19, 12:41 am, "Paul Lautman" <paul.laut...@btinternet.com>
wrote:
> JRough wrote:
> >I have tried this 4 2 weeks and I need some help. There are 3 other
> > pages referenced on this page but I'm going to start with this page
> > in case I missed something. It is called current_sightings.php. All
> > I want to do is redirect to Excel in the case of the External user.
> > The first if statement creates a form. The elseif redirects the
> > external user to only his own listings. I want the results for the
> > Internal user query SELECT_sightings_leasecars.() to go to my
> > current_sightingsXL.php page. Where/How would I put the redirect? I
> > think it should be after the switch for external users. The
> > getTableHeaders() function is the string that gets passed. All the
> > pages work except I can't redirect the output to Excel.

>
> What do you mean by "redirect the output to Excel"??? Excel isn't a
> location, it's a spreadsheet program that some (but not all users) will have
> on their machine.



I want it to out put to this page current_sightingsXL.php which is in
the same directory. I enclose the page. I also changed the url below
to be fully qualified. But I don't know where to put the redirect on
the first page current_sightings.



<?

require('./includes/config.inc.php');
# // current_sightingsXL.php
#// ################################################
#// Is the user logged in?

if(isset($_SESSION["LMS_LOGGED_IN"])){
$_SESSION["REDIRECT_AFTER_LOGIN"] = "current_sightings.php";
Header("Location: user_login.php");
exit;
}

include $include_path."LMS_functions.inc.php";



switch($param){
case 'current_sightings':
$result =
SELECT_sightings_leasecars($id,CLM_order_by($order _by));
break;
/*case 'cars_by_location':
$result = GetCars($lease_id);
break;
case 'idle_cars':
$result = GetRest($lease_id);
break;
case 'bad_order':
$result = GetRest($lease_id);
break;*/
default:
$result = SELECT_sightings_leasecars($id,CLM_order_by($order _by));
break;
}


if(!$result){
MySQLError($query);
exit;
}

$fields = mysql_num_fields($result);


for ($i = 0; $i < $fields; $i++) {
$header .= mysql_field_name($result, $i) . "\t";
}


while($row = mysql_fetch_row($result)) {
$line = '';
foreach($row as $value)
{
if ((!isset($value)) OR ($value == "")) {
$value = "\t";
} else {
$value = str_replace('"', '""', $value);
$value = '"' . $value . '"' . "\t";
}
$line .= $value;
}
$data .= trim($line)."\n";
}
$data = str_replace("\r","",$data);


if ($data == "") {
$data = "\n(0) Records Found!\n";
}

//$filename = GetFilename($lease_id)."_".$param;
$filename = "Current Sightings ";


header("Content-type: application/x-msdownload");
header("Content-Disposition: attachment; filename=".$filename.".xls");
header("Pragma: no-cache");
header("Expires: 0");
print "$header\n$data";







################################################## ############################################
################################################## ############################################
#######
####### QUERY FUNCTIONS
#######
################################################## ############################################
################################################## ############################################
function SELECT_sightings_leasecars($lease_id,$order_by) {
$query = "SELECT c.l_e,
c.car_mark, c.car_number,
c.location_city, c.location_state,
c.sighting_date,
e.classification,
c.railroad,
s.city as origin_city,
s.state as origin_state,
c.destination_city, c.destination_state,
t.eta
FROM INTERNAL_REMARK r, INTERNAL_CAR_LEASE cl,
clm_lastsighting_view v1,
clm_crossreference_view v2, INTERNAL_CODES e, INTERNAL_CLM c
LEFT JOIN (INTERNAL_TRIPS t, INTERNAL_SPLC s)
ON (c.trip_id = t.trip_id
AND t.origin_splc_id = s.splc_id)
WHERE cl.lease_id = ".$lease_id."
AND cl.end_date IS NULL
AND cl.remark_id = r.remark_id
AND r.car_mark = c.car_mark
AND c.car_mark = v1.car_mark
AND v1.car_mark = v2.car_mark
AND r.car_number = c.car_number
AND c.car_number = v1.car_number
AND v1.car_number = v2.car_number
AND c.sighting_date = v1.sighting_date
AND c.sighting_code = v2.code
AND c.sighting_code = e.code
ORDER BY ".$order_by;
$result = mysql_query($query);
if(!$result) {
MySQLError($query);
exit;
}
return $result;
}




?>

>
> BTW, Location: is supposed to take a fully qualified URL.



}elseif ($_POST['assign']=='Open in Excel'){

Header("Location: http://public_html/fakerockridge/current_sightingsXL.php?param=".$_Post['id']."&id=".
$_id);
Reply With Quote
  #7 (permalink)  
Old 07-19-2008
Bill H
 
Posts: n/a
Default Re: can't redirect to Excel

On Jul 19, 12:09*pm, JRough <jlro...@yahoo.com> wrote:
> On Jul 19, 12:41 am, "Paul Lautman" <paul.laut...@btinternet.com>
> wrote:
>
>
>
>
>
> > JRough wrote:
> > >I have tried this 4 2 weeks and I need some help. *There are 3 other
> > > pages referenced *on this page but I'm going to start with this page
> > > in case I missed something. *It is called current_sightings.php. *All
> > > I want to do is redirect to Excel in the case of the External user.
> > > The first if statement creates a form. * *The elseif redirects the
> > > external user to only his own listings. *I want the results for the
> > > Internal user query SELECT_sightings_leasecars.() to go to my
> > > current_sightingsXL.php page. *Where/How would I put the redirect? *I
> > > think it should be after the switch for external users. *The
> > > getTableHeaders() function is the string that gets passed. *All the
> > > pages work except I can't redirect the output to Excel.

>
> > What do you mean by "redirect the output to Excel"??? Excel isn't a
> > location, it's a spreadsheet program that some (but not all users) willhave
> > on their machine.

>
> I want it to out put to this page current_sightingsXL.php which is in
> the same directory. *I enclose the page. *I also changed the url below
> to be fully qualified. *But I don't know where to put the redirect on
> the first page current_sightings.
>
> <?
>
> require('./includes/config.inc.php');
> # // current_sightingsXL.php
> #// ################################################
> #// Is the user logged in?
>
> if(isset($_SESSION["LMS_LOGGED_IN"])){
> * * * * $_SESSION["REDIRECT_AFTER_LOGIN"] = "current_sightings.php";
> * * * * Header("Location: user_login.php");
> * * * * exit;
>
> }
>
> include $include_path."LMS_functions.inc.php";
>
> switch($param){
> * case 'current_sightings':
> * * * * * $result =
> SELECT_sightings_leasecars($id,CLM_order_by($order _by));
> * * * * * break;
> * /*case 'cars_by_location':
> * * * $result = GetCars($lease_id);
> * * * break;
> * case 'idle_cars':
> * * * * * $result = GetRest($lease_id);
> * * * * * break;
> * case 'bad_order':
> * * * $result = GetRest($lease_id);
> * * * break;*/
> * default:
> * * * * $result = SELECT_sightings_leasecars($id,CLM_order_by($order _by));
> * * * * break;
> * }
>
> if(!$result){
> * * MySQLError($query);
> * * exit;
>
> }
>
> $fields = mysql_num_fields($result);
>
> for ($i = 0; $i < $fields; $i++) {
> * * $header .= mysql_field_name($result, $i) . "\t";
>
> }
>
> while($row = mysql_fetch_row($result)) {
> * * $line = '';
> * * foreach($row as $value)
> {
> * * * * if ((!isset($value)) OR ($value == "")) {
> * * * * * * $value = "\t";
> * * * * } else {
> * * * * * * $value = str_replace('"', '""', $value);
> * * * * * * $value = '"' . $value . '"' . "\t";
> * * * * }
> * * * * $line .= $value;
> * * }
> * * $data .= trim($line)."\n";}
>
> $data = str_replace("\r","",$data);
>
> if ($data == "") {
> * * $data = "\n(0) Records Found!\n";
>
> }
>
> //$filename = GetFilename($lease_id)."_".$param;
> $filename = "Current Sightings ";
>
> header("Content-type: application/x-msdownload");
> header("Content-Disposition: attachment; filename=".$filename.".xls");
> header("Pragma: no-cache");
> header("Expires: 0");
> print "$header\n$data";
>
> ################################################## #########################*###################
> ################################################## #########################*###################
> #######
> ####### * * * * * * * * * * * * * * * * * * * * QUERY FUNCTIONS
> #######
> ################################################## #########################*###################
> ################################################## #########################*###################
> function SELECT_sightings_leasecars($lease_id,$order_by) {
> * $query = "SELECT c.l_e,
> * * * * * * * * * * * * * * * * * *c.car_mark, c.car_number,
> * * * * * * * * * * * * * * * * * *c.location_city, c.location_state,
> * * * * * * * * * * * * * * * * * *c.sighting_date,
> * * * * * * * * * * * * * * * * * *e.classification,
> * * * * * * * * * * * * * * * * * *c.railroad,
> * * * * * * * * * * * * * * * * * *s.city as origin_city,
> * * * * * * * * * * * * * * * * * *s.state as origin_state,
> * * * * * * * * * * * * * * * * * *c.destination_city, c.destination_state,
> * * * * * * * * * * * * * * * * * *t.eta
> * * * * * * * * * * * * FROM INTERNAL_REMARK r, INTERNAL_CAR_LEASE cl,
> clm_lastsighting_view v1,
> * * * * * * * * * * * * * * * * *clm_crossreference_view v2, INTERNAL_CODES e, INTERNAL_CLM c
> * * * * * * * * * * * * LEFT JOIN (INTERNAL_TRIPSt, INTERNAL_SPLC s)
> * * * * * * * * * * * * * * * * *ON (c.trip_id = t.trip_id
> * * * * * * * * * * * * * * * * *AND t.origin_splc_id = s.splc_id)
> * * * * * * * * * * * * WHERE cl.lease_id = ".$lease_id."
> * * * * * * * * * * * * AND cl.end_date IS NULL
> * * * * * * * * * * * * AND cl.remark_id = r.remark_id
> * * * * * * * * * * * * AND r.car_mark = c.car_mark
> * * * * * * * * * * * * AND c.car_mark = v1.car_mark
> * * * * * * * * * * * * AND v1.car_mark = v2.car_mark
> * * * * * * * * * * * * AND r.car_number = c.car_number
> * * * * * * * * * * * * AND c.car_number = v1.car_number
> * * * * * * * * * * * * AND v1.car_number = v2.car_number
> * * * * * * * * * * * * AND c.sighting_date = v1.sighting_date
> * * * * * * * * * * * * AND c.sighting_code = v2.code
> * * * * * * * * * * * * AND c.sighting_code = e..code
> * * * * * * * * * * * * ORDER BY ".$order_by;
> * $result = mysql_query($query);
> * if(!$result) {
> * * MySQLError($query);
> * * exit;
> * }
> * return $result;
>
> }
>
> ?>
>
>
>
> > BTW, Location: is supposed to take a fully qualified URL.

> }elseif ($_POST['assign']=='Open in Excel'){
>
> * * * * Header("Location:http://public_html/fakerockridge/current_sightingsXL.php?param=".$_Post['id']."&id=".
> $_id);- Hide quoted text -
>
> - Show quoted text -


I believe what you are trying to do is create an excel sheet on the
fly that would then open in their browser if it supports displaying
spread sheets in the browser, or be prompted to open / save if it
doesnt.

Is this is the case, you juust need to set the mime time of the
content that is coming to the user and not give them a location.

In perl you would do something like this:

print "Content-type: application/excel\n\n";
then print out the spreadsheet contents (probably in CSV format)

Bill H
Reply With Quote
  #8 (permalink)  
Old 07-19-2008
John Dunlop
 
Posts: n/a
Default Re: can't redirect to Excel

Bill H:

> print "Content-type: application/excel\n\n";


application/vnd.ms-excel is the registered MIME type.

> then print out the spreadsheet contents (probably in CSV format)


text/csv fits the bill.

application/x-msdownload is one of Internet Explorer's "known" MIME
types, but without wading through Microsoft's *cough* documentation of
this bu^H^Hfeature,* I don't know how Internet Explorer handles it.
Suffice to say, subtypes prefixed with "x-" are discouraged by RFC
2048, even more so when an appropriate type has already been
registered.

* http://msdn.microsoft.com/en-us/library/ms775147.aspx

--
Jock
Reply With Quote
  #9 (permalink)  
Old 07-19-2008
JRough
 
Posts: n/a
Default Re: can't redirect to Excel

On Jul 19, 10:54 am, John Dunlop <j...@dunlop.name> wrote:
> Bill H:
>
> > print "Content-type: application/excel\n\n";

>
> application/vnd.ms-excel is the registered MIME type.
>
> > then print out the spreadsheet contents (probably in CSV format)

>
> text/csv fits the bill.
>
> application/x-msdownload is one of Internet Explorer's "known" MIME
> types, but without wading through Microsoft's *cough* documentation of
> this bu^H^Hfeature,* I don't know how Internet Explorer handles it.
> Suffice to say, subtypes prefixed with "x-" are discouraged by RFC
> 2048, even more so when an appropriate type has already been
> registered.
>
> *http://msdn.microsoft.com/en-us/library/ms775147.aspx
>
> --
> Jock

Thanks for the link.

That is interesting. First I have been using Firefox but I am sure
that the users are using IE. So I will try it in IE on Monday. There
is no IE on the Mac.
This by the way seemed to works in my browser at leaset not saying it
is the right way or it works in IE.

>print "$header\n$data";
>print "Content-type: application/excel\n\n"


How would you add the csv extension? Something like this?
print "$header\n$data"."csv";
print "Content-type: application/vnd.ms-excel\n\n"

I'll see if I can figure out where to put the redirect on the first
page :-(

Reply With Quote
  #10 (permalink)  
Old 07-19-2008
Bill H
 
Posts: n/a
Default Re: can't redirect to Excel

On Jul 19, 3:13*pm, JRough <jlro...@yahoo.com> wrote:
> On Jul 19, 10:54 am, John Dunlop <j...@dunlop.name> wrote:
>
>
>
> > Bill H:

>
> > > print "Content-type: application/excel\n\n";

>
> > application/vnd.ms-excel is the registered MIME type.

>
> > > then print out the spreadsheet contents (probably in CSV format)

>
> > text/csv fits the bill.

>
> > application/x-msdownload is one of Internet Explorer's "known" MIME
> > types, but without wading through Microsoft's *cough* documentation of
> > this bu^H^Hfeature,* I don't know how Internet Explorer handles it.
> > Suffice to say, subtypes prefixed with "x-" are discouraged by RFC
> > 2048, even more so when an appropriate type has already been
> > registered.

>
> > *http://msdn.microsoft.com/en-us/library/ms775147.aspx

>
> > --
> > Jock

>
> Thanks for the link.
>
> That is interesting. *First I have been using Firefox but I am sure
> that the users are using IE. *So I will try it in IE on Monday. *There
> is no IE on the Mac.
> This by the way seemed to works in my browser *at leaset not saying it
> is the right way or it works in IE.
>
> >print "$header\n$data";
> >print "Content-type: application/excel\n\n"

>
> How would you add the csv extension? *Something like this?
> print "$header\n$data"."csv";
> print "Content-type: *application/vnd.ms-excel\n\n"
>
> I'll see if I can figure out where to put the redirect on the first
> page :-(- Hide quoted text -
>
> - Show quoted text -


I think (and I could be wrong) that with php you are used to using
print $header to get a header for an html page, but with perl we roll
our own header. In this case the header is:

print "Content-type: text/csv\n\n" (thanks John Dunlop)

For example (please excuse the use of perl code, I am learning php but
have been using perl for 10 years) if I wanted to send a simple CSV
(comma seperated value) spread sheet that contained a multiplication
table when they clicked on a link I would use the following code as
the address of the link they clicked:

#!/usr/bin/perl

print "content-type: text/csv\n\n";
print qq~"","1","2","3","4","5","6","7","8","9","10"\n~ ;
for($row = 1;$row < 11;$row++)
{
print qq~"$row"~;
for($col = 1;$col < 11;$col++)
{
$t = $row * $col;
print qq~,"$t"~;
}
print "\n";
}
exit;

Bill H
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 11:17 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0