Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

sebastian.virlan's avatar

Dynamic side-menu with count items

Hi, I would like to create a dynamic sidebar for a real estate website. In this moment the sidebar items are hard-coded with a lot of ul, li. I wan't that the client to be free and to let him add any links with filters in the future.

What I want to do is to put all this items in a table, with a parent column (to make it recursive). But how can I get the URL and the count? For example the URL for sale 4 rooms apartments is something like this:

http://example.com/sale-apartments/rooms-4/

From a city:

http://example.com/sale-apartments/city-washington/rooms-4/

(I found this question reliable only to my problem, if is not ok posting here I will delete it, thank you.)

0 likes
6 replies
Osman's avatar

The links you attached in your question won't work , because it's only reachable from your computer.

jkarthikeyan's avatar

Hi Sebastian

First of all get count of all items from server and based on category list them out into ul li and apply filter on it . And as Osman said put the live url links so we can test it.

1 like
sebastian.virlan's avatar

I know about link of course, sorry for confuse you, it was only for example. I will modify into example.com . I don't have a live preview of the website as is on development on localhost. What I think until now is to have this table:

For this link: http://example.com/sale-apartments/city-washington/rooms-4/

Table: sidebar

Columns:

  • name (i.e 4 rooms)
  • filters (a JSON with the filters? like: {'transaction':'sale', 'type':'apartment', 'city':'washington', 'rooms': '4'} and based on this to build the URL and count? )
  • parent (fk to sidebar itself table)
  • order (integer, the order of items)
sebastian.virlan's avatar

Also to count on 20 - 30 list items can be problematic from the performance side. I should store the count for each filter somewhere I think or I run out of idea.

sebastian.virlan's avatar

@jkarthikeyan I don't think is a good idea because the filters depends on 6 - 7 tables (is a real estate database, with cities, streets, areas and a lot of other joins).

Please or to participate in this conversation.