LEFT JOINs and other JOINs

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
kanshou
Forum Commoner
Posts: 47
Joined: Sun Aug 03, 2003 1:57 pm
Location: San Diego
Contact:

LEFT JOINs and other JOINs

Post by kanshou »

I have two columns in two different tables that share ID's. I need to call all of the rows in Table 2 that have the same ID as a row in table 2
for example:
Table 1___________________|___Table 2__________
ID___Desciption__________________ID__Description
1____Room a_____________________1____desk 1
________________________________1____desk 2
________________________________1____desk 3
Here is my SQL Query

Code: Select all

<?php
$sql = "SELECT webcal_entry.cal_name, webcal_entry.cal_description, webcal_entry.cal_date, webcal_entry.cal_time, webcal_entry.cal_id, ";

  $sql .= "webcal_entry.cal_ext_for_id, webcal_entry.cal_priority, webcal_site_extras.cal_data, webcal_entry.cal_access, webcal_entry.cal_duration, ";

  $sql .= "webcal_entry_user.cal_status, webcal_entry_user.cal_login ";

  if ( $want_repeated ) {

    $sql .= ", webcal_entry_repeats.cal_type, webcal_entry_repeats.cal_end, webcal_entry_repeats.cal_frequency, webcal_entry_repeats.cal_days ";

    $sql .= "FROM webcal_entry_repeats, webcal_entry_user, webcal_entry LEFT JOIN webcal_site_extras ON webcal_entry.cal_id = webcal_site_extras.cal_id ";

    $sql .= "WHERE webcal_entry.cal_id = webcal_entry_repeats.cal_id AND ";

  } else {

    $sql .= "FROM webcal_entry LEFT JOIN webcal_site_extras ON webcal_entry.cal_id = webcal_site_extras.cal_id ";

    $sql .= "RIGHT JOIN webcal_entry_user ON webcal_entry_user.cal_id = webcal_entry.cal_id WHERE ";

  }
  $sql .= "webcal_entry_user.cal_status IN ('A','W') ";
?>
Now, the problem with this is, it doesn't work. I can't get it to display all of the "desk" information as I laid out in the quote above. I am also getting the following error.
Warning: date(): Windows does not support dates prior to midnight (00:00:00), January 1, 1970 in c:\nusphere\apache\nsdocs\apps\webcalendar\includes\functions.php on line 1358

Warning: Cannot modify header information - headers already sent by (output started at c:\nusphere\apache\nsdocs\apps\webcalendar\includes\functions.php:1358) in c:\nusphere\apache\nsdocs\apps\webcalendar\includes\functions.php on line 252
Redirecting to ... here..
Warning: mysql_close(): supplied argument is not a valid MySQL-Link resource in c:\nusphere\apache\nsdocs\apps\webcalendar\includes\php-dbi.php on line 117
Post Reply