Quote:
Originally Posted by miki86
You have relative ID's stored in your db as i understand.
Use that ID to load different subcategories.
Example:
categories.php
PHP Code:
// You can do a loop here if you have to many categories <a href="subcategories.php?catid=1">Category 1</a> <a href="subcategories.php?catid=2">Category 2</a> <a href="subcategories.php?catid=3">Category 3</a> <a href="subcategories.php?catid=4">Category 4</a>
subcategories.php
PHP Code:
if(isset($_GET['catid']) && ($_GET['catid'] != NULL)) $categoryID = $_GET['catid']; else $categoryID = 1; $query = "SELECT * FROM subcategories WHERE parentID = {$categoryID}"; $result = mysql_result($query);
while($row = mysql_fetch_assoc($result)) { echo $row[]; }
Something like that should work.
EDIT:
btw im looking at your files and i noticed this in your subcategories.php:
PHP Code:
$sub_cats = $_GET['parentid'];
$query = "SELECT * FROM categories WHERE parentid != 0";
You are passing a parentid value, but you are not using it in your sql
Your query should look like this:
PHP Code:
$sub_cats = mysql_real_escape_string($_GET['parentid']);
$query = "SELECT * FROM categories WHERE parentid = {$sub_cats}";
|
Hi Miki,
I've tried to use your code posted above, and I am getting this error:
Code:
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /var/www/subcategories.php on line 17
Line 17:
PHP Code:
while($row=mysql_fetch_assoc($result)) {
I do have the closing curly brace btw. I just posted the line with the error, and I did put 'name' in the $row[]; part in the while loop, assuming that will give me the names of the subcategories for each of the categories in the database. Yes, I also do have subcategories in the subcategories table.
It might be better if you could offer an sql file that I can import to get the database structure you offering me. Otherwise, I am having a total brain freeze trying to figure this out...I am pretty good with navigation, but until I have the coding part understood, I am a total n00b. Give me credit, I am still trying though.
Thanks again for the help in advance!
-Brian
__________________
Made2Own
Last edited by Brian07002; 02-02-2012 at 10:44 PM..
|