Hi, hope you can all be as helpful as usual!
I'm developing a site for a bookseller and on each book's detail page I've got a 'titles by the same author' list (a recordset called 'authormatch'). I can get this list fine, but I obviously I don't want the book whose page it is to also appear on this list.
The 'books' table has an 'id' column which is called by a URL variable 'book_id'. However if I simply insert
AND books.id !=". $_GET['book_id']."
into my authormatch query, it doesn't leave out the row I want it to. I can't understand why!
Here's the complete code for retrieving the authormatch rows:
if($row_book['author'] !=NULL) {
mysql_select_db($database_allauto, $allauto);
if($row_book['author3'] !=NULL) {
$query_authormatch = "SELECT books.id, books.title, books.author, books.author2, books.author3 FROM books
WHERE books.author LIKE '%" . $row_book['author'] . "' OR books.author LIKE '%" . $row_book['author2'] . "' OR books.author LIKE '%" . $row_book['author3'] . "'
OR books.author2 LIKE '%" . $row_book['author'] . "' OR books.author2 LIKE '%" . $row_book['author2'] . "' OR books.author2 LIKE '%" . $row_book['author3'] . "'
OR books.author3 LIKE '%" . $row_book['author'] . "' OR books.author3 LIKE '%" . $row_book['author2'] . "' OR books.author3 LIKE '%" . $row_book['author3'] . "'
AND books.id !=".$_GET['book_id']." ORDER BY books.title ASC";
} elseif ($row_book['author2'] !=NULL) {
$query_authormatch = "SELECT books.id, books.title, books.author, books.author2, books.author3 FROM books
WHERE books.author LIKE '%" . $row_book['author'] . "' OR books.author LIKE '%" . $row_book['author2'] . "'
OR books.author2 LIKE '%" . $row_book['author'] . "' OR books.author2 LIKE '%" . $row_book['author2'] . "'
OR books.author3 LIKE '%" . $row_book['author'] . "' OR books.author3 LIKE '%" . $row_book['author2'] . "'
AND books.id !=".$_GET['book_id']." ORDER BY books.title ASC";
} else {
$query_authormatch = "SELECT books.id, books.title, books.author, books.author2, books.author3 FROM books
WHERE books.author LIKE '%" . $row_book['author'] . "' OR books.author2 LIKE '%" . $row_book['author'] . "' OR books.author3 LIKE '%" . $row_book['author'] . "'
AND books.id !=" . $_GET['book_id'] . " ORDER BY books.title ASC";
}
$authormatch = mysql_query($query_authormatch, $allauto) or die(mysql_error());
$row_authormatch = mysql_fetch_assoc($authormatch);
$totalRows_authormatch = mysql_num_rows($authormatch);
}
Any ideas people?