A little bit ago, I posted on here about the way I had my db tables setup and the queries I was doing, and I got a lot of helpful ideas to straighten them out. I did all that and redid my table structures and the way it queries, etc and everything loads much faster and works a lot better. But there is one area that I having trouble with where I want to display a "blank" image in the table for where they do not own the item
For example, I have the db tables setup this way
books
id (unique, the book id)
name
title
category
userbooks
id (auto incr to give unique key to table)
username
bookid (will be the id in the books table)
If I want to display every book they own for a certain category, I do this:
//this is coming from form or somewhere, etc
$cat="fiction";
$result = mysql_query("select books.* from books, userbooks where books.id=userbooks.bookid AND books.category='$cat' AND userbooks.username='{$logged["name"]}'" );
while ( $book = mysql_fetch_array($ret) )
{
//put in image of the book and other info from the books.* in the form of a table
}
That part there works great and I have no problems with it, but there is one instance on the site where I want to display every book, even the ones they DO NOT own, but I am not sure how to query it to do that, the only way I know to do is the multiple query way I was doing previously
$cat="fiction";
//get all the books for this cat
$result = mysql_query( "select * from books where category='$cat'" );
while ( $booklist = mysql_fetch_array($result) )
{
//find out if they own this book or not
$check = @db_query("select * from userbooks where bookid='{$booklist["id"]}' AND username='{$logged["name"]}'" );
if ( $book = mysql_fetch_array($check) )
{
//they have an entry in the table, so they own the book
//put in image of the book and other info from the booklist array in the form of a table
}
else
{
//they have no entry, so they don't own the book
//put in a "blank image" in the table <td>
}
} //end while
That's the basics of what I want to do for this part, I am trying to clean this part up like the code above where it runs more efficiently, but I can't figure out to make it draw the blanks doing the 1 multiple table query
And of course I'm at work and didn't copy/paste this, so ignore the typos/parser errors, lol