I'm stumped again. I'm working with two tables. One is a table of events. The other is a table of dates and times for those events.
It's possible to have multiple dates for an event. It's also possible to have NO dates for an event, but I want to highlight such events so the user will remember to add dates for them.
I'm doing a left join of the two tables using the join condition "eventid". Every event has a unique "eventid", and every event date has an "eventid" for the event it's associated with.
When I do this:
$result = mysql_query("SELECT * FROM cpevents left join cpeventdates ON cpeventdates.eventid = cpevents.eventid WHERE cpeventdates.eventid is NOT NULL ORDER BY startdate",$db);
while ($myrow = mysql_fetch_array($result)) {
printf("<a href=\"%s?eventdateid=%s&adddates=yes&eventname=%s\">%s</a>\n", $PHP_SELF, $myrow["eventdateid"], $myrow["eventname"], date('M d, Y', strtotime($myrow["startdate"])));
printf("<a href=\"%s?eventid=%s&createedit=yes\"><b>%s</b></a>\n", $PHP_SELF, $myrow["eventid"], $myrow["eventname"]);
printf("<a href=\"%s?eventid=%s&adddates=yes&eventname=%s\">Dates & times</a>", $PHP_SELF, $myrow["eventid"], $myrow["eventname"]);
printf("<a href=\"%s?eventid=%s&delete=yes&eventname=%s\">[delete event]</a></br>", $PHP_SELF, $myrow["eventid"], $myrow["eventname"]);
}
echo "<br>";
$result = mysql_query("SELECT * FROM cpevents left join cpeventdates ON cpeventdates.eventid = cpevents.eventid WHERE cpeventdates.eventid is NULL ORDER BY eventname",$db);
while ($myrow = mysql_fetch_array($result)) {
printf("<a href=\"%s?eventid=%s&createedit=yes\"><b>%s</b></a>\n", $PHP_SELF, $myrow["eventid"], $myrow["eventname"]);
printf("<a href=\"%s?eventid=%s&adddates=yes&eventname=%s\">Dates & times</a>", $PHP_SELF, $myrow["eventid"], $myrow["eventname"]);
printf("<a href=\"%s?eventid=%s&delete=yes&eventname=%s\">[delete event]</a><br>", $PHP_SELF, $myrow["eventid"], $myrow["eventname"]);
}
...it looks perfect. Two tables (ok - i stripped away the table formatting for clarity), one with dates and events, the other with events that don't have dates.
The problem is, while the links created in the first query show the proper "eventid" when moused over (and clicked on), the links in the second query don't. I get
"...addevent.php?eventid=&addates=yes&eventname=Birthday Party"
instead of
"...addevent.php?eventid=3&addates=yes&eventname=Birthday Party"
So the eventname is being passed along properly, but the eventid is disappearing. I think this has something to do with eventid being the join condition between the two tables. There is no eventid in the right-hand table (cpeventdates), but there is in the left-hand table so there ought to be something in there for $myrow["eventid"] to return.
Any idea how to fix this?