I'm brand new to PHP and MySQL and as my first project I'm trying to build category navigation from a single table named testdata. Columns in the table are: recordid, category, subcategory, and detail.
I use one php script (cat1.php) to query the table and display a distinct list of top level categories as links. That works fine. The links are displayed with:
<a href=\"cat2.php?category={$row['category']}\">{$row['category']}</a>
Each link goes to cat2.php?category=CATEGORYNAME, and cat2.php is supposed to query the subcategory column using $_GET to determine the subcategories to display. This is my query in cat2.php:
$query = "SELECT DISTINCT(testdata.subcategory), testdata.category FROM testdata WHERE testdata.category = {$_GET['category']}";
This doesn't work. However, I've tried using recordid instead of category (as in cat2.php?recordid=RECORDID), which is a unique key field, and that does work. Obviously that returns every record, however, when I'm really just trying to return distinct subcategories.
My point is that the query works when $_GET is looking for a number, but it doesn't work when it's looking for a VARCHAR or TEXT value. Why would this be? Is something inherently wrong with my method? Take it easy now, I'm brand new to this ๐
I know this may not be the smartest method, but I'm using this as a basic model to help me learn. I've figured out how to accomplish the same functionality if I have separate tables for categories and detail items, but in the future I will receive data in a single table every day and I don't want to have to manipulate it.
Thank you,
IgnatiusR