I have an sqlite database of books that i am able to display, however I want to be able to filter this display if the user clicks a spesific category. I have the following code to load the categorys
echo "<div> <a href='index.php?category1=1'> The PHP Programming Series </a> <a href='index.php?category2=1'> TCP-IP for Beginners Series </a> <a href='index.php?category3=1'> Client Side Programming Series </a> <a href='index.php?category4=1'> The Web Design Series – an HCI focus </a> </div>";
which correctly redirects the user to the spesific page. then, for the relevant page (in this example, category1) i have the following code
else if(isset($_GET['category1'])) {
//The PHP Programming Series
$category = 'The PHP Programming Series';
echo "<p>
<a href='./index.php'>Bookshop</a></p>";
echo "<h3>Search Results</h3>";
echo "<table style='width:500px;' cellspacing='0'>";
echo "
<tr>
<th style='border-bottom:1px solid #000000;'></th>
<th style='border-bottom:1px solid #000000;'>Title</th>
<th style='border-bottom:1px solid #000000;'>Brief Description</th>
<th style='border-bottom:1px solid #000000;'>Author</th>
<th style='border-bottom:1px solid #000000;'>Price</th>
</tr>";
if(sqlite_num_rows($result) !=0) {
foreach($products as $id => $product) {
if($product['cat1'] = $category) {
echo "<tr>
<td style='border-bottom:1px solid #000000;'><a href='./index.php?view_product=$id'><img src='/img/" . $product['imgNumber'] . ".jpg' /></a></td>
<td style='border-bottom:1px solid #000000;'><a href='./index.php?view_product=$id'>" . $product['Title'] . "</a></td>
<td style='border-bottom:1px solid #000000;'>" . $product['Brief_Synopsis'] . "</td>
<td style='border-bottom:1px solid #000000;'>" . $product['Author'] . "</a></td>
<td style='border-bottom:1px solid #000000;'>£" . $product['price'] . "</td>
</tr>";
} else {
continue;}
} } else {
echo "<p> No Results </p>";}
echo "</table>";
}
However, its like the if statement if($product['cat1'] = $category) is true everytime because every book in my database still displays and the else continue does not work.
here is an example of the first two books in my database
sqlite_query($db,"INSERT INTO Books (Author, Title, Brief_Synopsis, ISBN_Number, Publisher, imgNumber, price, cat1, cat2) VALUES ( 'Mike McGrath', 'C Programming In Easy Steps 4th Edition','C Programming in easy steps has an easy-to-follow style that will appeal to anyone who wants to begin programming in C', 1840785446, 'In Easy Steps Limited', '001', 24.99, 'Client Side Programming Series', 'Programming')");
sqlite_query($db,"INSERT INTO Books (Author, Title, Brief_Synopsis, ISBN_Number, Publisher, imgNumber, price, cat1, cat2) VALUES ( 'Robin Nixon', 'Learning PHP, MySQL & JavaScript: With jQuery, CSS & HTML5','Build interactive data-driven websites with the potent combination of open-source technologies and web standards', 9781491918661, 'O'Reilly', '002', 40.99, 'The PHP Programming Series','Programming')");
however there are 20 books in my database and users can add more.
How can i get this to only display books with matching category?