//Gets all the column names from the table
SetToolsDB();
$SQL="SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.Columns where TABLE_NAME = 'htm_book'";
$fields = mysql_db_query($dbname, $SQL) or die("Failed Query of " . $SQL); //do the query
$fieldCount = mysql_numrows($fields);
$bookCats="";
//Start at 46 because that is the start of the category listings
for($i=46;$i<$fieldCount;$i++){
//Checks to see if current book is part of category and that the column name isn't anything we don't want
if(mysql_result($book,0,$i)==1 && mysql_result($fields,$i,0)!="EBAY_OMIT"){
if($bookCats!=""){
//if already set adds OR and then the column
$bookCats=$bookCats." OR ".mysql_result($fields,$i,0);
}else{
$bookCats=mysql_result($fields,$i,0);
}
}
}
//if book categories found the pull a set of 4 random books to display.
if($bookCats!=""){
$SQL = "SELECT * FROM htm_book WHERE BK_PRICE<>'0.00' AND IS_CLONE=0 AND NTL_IDNO<>".$_GET['item']." AND ($bookCats) ORDER BY RAND() LIMIT 4";
$suggestedBooks = mysql_db_query($dbname, $SQL) or die("Failed Query of " . $SQL); //do the query
$suggestedBooksCount = mysql_numrows($suggestedBooks);
}
?>
if($bookCats!=""){?>