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

  • Home
  • SEARCH
  • 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 6342591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:16:08+00:00 2026-05-24T20:16:08+00:00

I have the following sql query SELECT * FROM jos_jcalpro_events AS e LEFT JOIN

  • 0

I have the following sql query

SELECT * FROM jos_jcalpro_events AS e 
  LEFT JOIN jos_jcalpro_events_seats AS s ON e.extid = s.extid
  LEFT JOIN jos_jcalpro_events_types_xref AS t ON e.extid = t.extid

which I execute via PDO from PHP. I create out of this another query to reinsert in the database. But it doesn’t work. When I change LEFT from upper to lower case it does:

SELECT * FROM jos_jcalpro_events AS e 
  left JOIN jos_jcalpro_events_seats AS s ON e.extid = s.extid
  left JOIN jos_jcalpro_events_types_xref AS t ON e.extid = t.extid

In my creating routine there is no difference but the created INSERT has actually 2 lines less. How can that be?

Here is the important part of the code:

    $resource = JcalproDataImport::getInstance();

    // IMPORT
    $pdo = $resource->getConnection('import', 'pdo');
    $events = $pdo->query(
        'SELECT * FROM jos_jcalpro_events AS e '
        .'left JOIN jos_jcalpro_events_seats AS s ON e.extid = s.extid '
        .'left JOIN jos_jcalpro_events_types_xref AS t ON e.extid = t.extid;')->fetchAll(PDO::FETCH_ASSOC);

    // MAPPING
    $map = array(
        'picture'=>null, 'cat'=>null, 'day'=>null, 'month'=>null, 'year'=>null, 'recur_type'=>null, 'checked_out'=>null,
      'checked_out_time'=>null, 'payment_type'=>null, 'id'=>null,
      'extid'=>'id', 'contact'=>'contact_info', 'start_date'=>'start', 'end_date'=>'end', 'recur_val'=>'repeat_period',
      'recur_end_type'=>'repeat_end_type_id', 'recur_count'=>'repeat_end_after_occurrences',
      'recur_until'=>'repeat_end_after_date', 'wp_only'=>'only_in_wp', 'eticket'=>'prevent_sending_eticket',
      'region'=>'region_id', 'onlinebooking'=>'online_booking_form', 'organiser'=>'organiser_name'
    );

    // OUTPUT
    $pdo = $resource->switchConnection('export', 'pdo');
    $pdo->query('SET foreign_key_checks = 0');

    foreach ($events as $values)
    {
        $values['chargeable_status'] = (strtolower($values['payment_type']) == 'p') ? 1 : 0;
        $values['repeat_period_type_id'] = $repeat_period_type_map[$values['recur_type']];
        foreach($map as $from=>$to)
        {
            if ($to!== null){ $values[$to] = $values[$from]; }
            unset( $values[$from] );
        }
        $values['created_at'] = '2008-01-01';
        $values['updated_at'] = $values['created_at'];

          if (!$event) {
              foreach ($values as $field=>$value)
              {
                  $sql .= ', '.$field;
                  $sqlValues .= ', "'.mysql_real_escape_string($value).'"';
              }
              $sql = 'INSERT INTO event ( '.substr($sql, 2).' ) VALUES '.PHP_EOL.'( '.substr($sqlValues, 2).' )';
          }else{
              foreach ($values as $value)
              {
                  $sqlValues .= ', "'.mysql_real_escape_string($value).'"';
              }
              $sql .= ', ( '.substr($sqlValues, 2).' )';
          }
        $event[] = $values;
    }
    $pdo->query($sql)

But it works fine for other queries, so that I can’t believe in a problem there.

  • 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-05-24T20:16:11+00:00Added an answer on May 24, 2026 at 8:16 pm
    1. There is no reason left JOIN would work differently than LEFT JOIN. That’s very unlikely to be related to your problem.

    2. Do your column name mapping with column aliases in your SELECT.

    3. Omit columns you don’t want by naming those columns you do want, instead of using SELECT *.

    4. Prepare the INSERT once, with named parameters matching the column alias names. Then use execute($values) to insert each row fetched from the SELECT.

    Here’s approximately how I’d write it:

    $map = array(
      'extid'=>'id', 
      'contact'=>'contact_info', 
      'start_date'=>'start', 
      'end_date'=>'end',
      'recur_val'=>'repeat_period', 
      'recur_end_type'=>'repeat_end_type_id', 
      'recur_count'=>'repeat_end_after_occurrences',
      'recur_until'=>'repeat_end_after_date',
      'wp_only'=>'only_in_wp',
      'eticket'=>'prevent_sending_eticket',
      'region'=>'region_id',
      'onlinebooking'=>'online_booking_form',
      'organiser'=>'organiser_name',
      'CURDATE()'=>'created_at',
      'CURDATE()'=>'updated_at',
    );
    
    $aliasize = function($alias, $column) { return "$column AS $alias"; }
    $select_list = join(",", array_walk($aliasize, $map));
    
    $events = $pdo->query("SELECT $select_list FROM ...")
        ->fetchAll(PDO::FETCH_ASSOC);
    
    $column_list = join(",", array_values($map));
    $parameterize = function($alias) { return ":$alias"; }
    $param_list = join(",", array_map($parameterize, $map));
    
    $insert = $pdo->prepare("INSERT INTO event ($column_list) VALUES ($param_list)");
    
    foreach ($events as $values) {
        $insert->execute($values);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a following SQL QUERY: SELECT articles.name, articles.price, users.zipcode FROM articles INNER JOIN
I have the following SQL query: select expr1, operator, expr2, count(*) as c from
I have the following SQL query: SELECT * FROM table WHERE field_1 <> field_2
I have the following SQL query: SELECT Phrases.* FROM Phrases WHERE (((Phrases.phrase) Like *ing
I have the following SQL query: select AuditStatusId from dbo.ABC_AuditStatus where coalesce(AuditFrequency, 0) <>
I have the following SQL query: select ID, COLUMN1, COLUMN2 from (select ID, COLUMN1,
I have the following Linq to SQL query, in which I'm trying to do
I have the following query in iSeries SQL which I output to a file.
I have the following SQL-statement: SELECT DISTINCT name FROM log WHERE NOT name =
I have the following query: SELECT FROM tblMailToSend WHERE (DateToSend < @dateToSend OR DateToSend

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.