Jump to content

Some logic help please!


herghost

Recommended Posts

Hi all, Its been a while since I looked at PHP and I have forgotten some basics

What I am trying to achieve is display category names, sub categories and results into a list

 

<ul id="nav">
<li><a href="#">Main Cat</a>
<ul>
	<li><a href="#">Sub Cat 1</a>
		<ul>
			<li><a href="#">result</a></li>
			<li><a href="#">result</a></li>

		</ul>
	</li>
                <li><a href="#">Sub Cat 2</a>
		<ul>
	              <li><a href="#">result</a></li>
	              <li><a href="#">result</a></li>
	        </ul>
</ul>
</li>

 

What would be the best way to organise my database? Have everything in one entry like:

 

main_id / sub_id / listing_id / listing_name

 

or separate them into a table for cats, one for sub cats and what parent it belongs to, then a table for the listings linking to the sub cat it belongs to?

 

I have confused myself no end on how then to display the results, so any help with would be gratefully received!

 

Thanks

 

Dave

 

 

Link to comment
https://forums.phpfreaks.com/topic/257827-some-logic-help-please/
Share on other sites

Hello Dave,

 

Personally I would structure the database in the following way...

 

Table 1 - Holds your main categories, their descriptions etc.
Table 2 - Holds the sub-categories, their descriptions etc which is linked in with `mainCatID` or something similar.
Table 3 - Holds the listings themselves with the information and a `subCatID` field or something like it.

 

So you can then iterate through your main categories. Whilst you do that you can then iterate through the subcategories and within that the listings for that specific subcategory.

 

Main Category (Loop) -> Sub Category (Loop) -> Listing (Loop).

 

It isn't the cleanest way you could do it but certainly something to then build on.

 

Hope it helps.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.