I have two tables that I'm getting data from: 1) the 'lessons' table which stores all the information I want to print and 2) 'lesson_categories' which associates each lesson with multiple categories.
I'm trying to retrieve all the lessons that don't have any category associated with them. So, I have the following query:
"SELECT * FROM lessons
LEFT JOIN lesson_categories ON
lessons.lessonid=lesson_categories.lessonid
WHERE (lesson_categories.categoryid IS NULL
OR lesson_categories.categoryid = 0) AND lessons.active > 0"
The query works great and returns the correct rows.
However, I can't print the auto_increment id field: lessonid. My code is below. It will print all the fields except the lessonid. The problem is with the query, b/c if I change the query to a simple SELECT * FROM TABLE... it will print the id just fine.
<?
$results = mysql_query("SELECT * FROM lessons
LEFT JOIN lesson_categories ON
lessons.lessonid=lesson_categories.lessonid
WHERE (lesson_categories.categoryid IS NULL
OR lesson_categories.categoryid = 0) AND lessons.active > 0");
$numrec = db_num_rows($results);
IF ($numrec > 0) {
$row = mysql_fetch_assoc ($results);
$lessonid = $row['lessonid'];
$title = $row['title'];
$created = date("m/d/y",$row['created']);
echo $lessonid;
echo $title;
echo $created;
}
?>
What's the problem? Should I be using a different query?