Copy link to clipboard
Copied
I have created a site which advertises companies in all counties of the UK. I have created a drop down menu on the home page so you can select the county you want to search in. Currently all my adverts are placed in the site and the drop down menu is redundant. I would like it so when the user selects the county from the drop down list it filters all the adverts and only shows the adverts in that area, but if no county is selected it will show all the adverts.
Can anyone suggest the best solution to handle this request.
The site is currently online at:
You can see the drop down menu is not yet fully populated with all the counties yet but does not currently function.
Copy link to clipboard
Copied
The typical way to do this would be to store the content data in a database and build the pages dynamically using a server-side language like PHP.
So, in your database, you would have a table called something like ADVERTS, which would have columns for COMPANY, COUNTY, CATEGORY (such as for Cars, Health, Dining, etc.) and any other relevant columns.
Then, when the visitor selects a COUNTY from the dropdown and a CATEGORY from the menu, the page will be populated according to a database query, such as the following:
SELECT * FROM ADVERTS WHERE COUNTY='$county' AND CATEGORY='$category'
Using this method, you would not have a website with hundreds of pages, but a website with just a few pages that are populated with the releveant content based on the database query. In fact, your whole website could be built using just four or five HTML pages, with all the content being pulled from a database. I don't think there is any other way to achieve what you are after.
Copy link to clipboard
Copied
Thank you for the reply.
Can the database store images? All my adverts are jpeg images.
Copy link to clipboard
Copied
In theory the database can store images, but I can promise you that it isn't necessary or advisable to do so. what you do is upload the image to a directory and store the image file name in the database. so if the images are stored in a folder called "images" the database may simply store the name, like "cocacola.jpg." This would be stored in the same ADVERT table along with the other info.
Then (sing PHP) the image url looks something like this:
<img src="/images/<?php $advert_image ?>"/>
You can also, of course, add the alt tag, image size tags and CSS. The above is just the minimal to demonstrate the point.
Copy link to clipboard
Copied