Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7850961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:02:56+00:00 2026-06-02T19:02:56+00:00

I’m making a temporary table which is a summary of data from two other

  • 0

I’m making a temporary table which is a summary of data from two other tables, and outputting it to a spreadsheet.

The tables are ‘cruises’ and ‘itinerary’ and the cruises table lists out some cruises , and related to that table by the id is the itinerary table, which contains a row for each port of call on that cruise.

cruise table:

  • id, title, departure, code, duration

itinerary table:

  • id, cruise_id, day, port, order

I want to put that data together, like this

  • cruise_id: the id of the cruise
  • description field contains all of the ports that the cruise visits,
    separated with commas, and maybe even ordered by the day of the cruise

Here’s the code so far, I haven’t selected anything from the itinerary table yet

<?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('&nbsp;'),'',$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";
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T19:02:56+00:00Added an answer on June 2, 2026 at 7:02 pm

    You are looking for the GROUP_CONCAT function in MySQL.

    This will allow you to group by cruise_id, and order by day.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text area in my form which accepts all possible characters from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.