tags:

views:

52

answers:

2

I want a list of all threads of the forum ID I'm viewing, but I also want to get information about the forum I'm viewing, like name and description. My query wont work:

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in forum.php on line 11

How would I join in my forums table in this query?

$tresult = mysql_query("SELECT * FROM threads WHERE threads.forumID = ".intval($_GET['forumID'])." LEFT JOIN forum ON forum.id = threads.forumID");

// does the forum even exist?
if (mysql_num_rows($tresult) < 1) {
  // Show error and return
  echo "The forum you are looking for appears to be missing.";

  return false; 
}

if ($is_l

My tables:

  • forum: id, name, description
  • threads: id, forumID, title, body, date
A: 

where should go after the join.

try: mysql_query(...) or die(mysql_error());

to see the error msg

jspcal
+6  A: 

You must write the JOIN before the WHERE clause:

SELECT *
FROM threads
LEFT JOIN forum ON forum.id = threads.forumID
WHERE threads.forumID = $forumID

Also, you should look at using parameters instead of using string appending to create your queries. It's probably safe enough here since you are using intval but if you make a habit of building SQL queries using string appending you will slip up eventually.

Mark Byers