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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.