我正在创建一个临时表,它是来自其他两个表的数据摘要,并将其输出到电子表格。
这些表是'巡航'和'行程',巡航表列出了一些巡航,并且id与该表相关的是行程表,其中包含该巡航上每个停靠港口的一行。
巡航表:
行程表:
我想将这些数据放在一起,就像这样
到目前为止,这是代码,我还没有从行程表中选择任何东西
<?php require_once('includes/session.php'); ?>
<?php require_once('includes/connection.php'); ?>
<?php require_once('includes/functions.php'); ?>
<?php confirm_logged_in(); ?>
<?php
$maketemp = "CREATE TEMPORARY TABLE temp(`itineraryId` int NOT NULL, `live` varchar(1), `shipCode` varchar(15), `description` text, `length` varchar(10), PRIMARY KEY(itineraryId))";
mysql_query( $maketemp, $connection ) or die ( "Sql error : " . mysql_error ( ) );
$inserttemp = "INSERT INTO temp SELECT id AS itineraryId, live, ship AS shipCode, description AS description, duration AS length FROM cruises WHERE live ='Y'";
mysql_query( $inserttemp, $connection ) or die ( "Sql error : " . mysql_error ( ) );
$select = "SELECT itineraryId, shipCode, description, length FROM temp";
$export = mysql_query ( $select, $connection ) or die ( "Sql error : " . mysql_error( ) );
$fields = mysql_num_fields ( $export );
for ( $i = 0; $i < $fields; $i++ )
{
$header .= mysql_field_name( $export , $i ) . "\t";
}
while( $row = mysql_fetch_row( $export ) )
{
$line = '';
foreach( $row as $value )
{
if ( ( !isset( $value ) ) || ( $value == "" ) )
{
$value = "\t";
}
else
{
$value = strip_tags( $value );
$value = str_replace( array(' '),'',$value );
$value = str_replace( array('Ocean Countess'), 'OC', $value );
$value = str_replace( array('Marco Polo'), 'MP', $value );
$value = str_replace( array('Nights', 'nights', 'Night', 'night'), '', $value);
$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";
}
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=itinerary.xls");
header("Pragma: no-cache");
header("Expires: 0");
print "$header\n$data";
?>