Hello,
I am implementing a banner ads system on my website. I will allow users to create banner ads with different display options.
A simple mysql query will look like this:
$banner = mysqli_query($connection1,"SELECT select banner_image, url FROM banners WHERE banner_active='1' order by exposures ASC limit 0,1") or die('Error');
So far there is no problem. I create an index on columns banner_active, exposures and that's all.
But the users will be allowed to select provinces where to show their ads and to select genders (male, female, other or all 3) whom to show their ads. There are 50 provinces in Spain and I can add 50 columns to the table but it's not a solution because of the gender option. I can add 3 columns for genders but then I can't create so many indexes.
If I show a banner ad for a male visitor from province of Las Palmas, the query should look like this:
$banner = mysqli_query($connection1,"SELECT select banner_image, url FROM banners WHERE banner_active='1' amd province1='1' and gender1='1' order by exposures ASC limit 0,1") or die('Error');
So, in this example I need an index on columns banner_active, province1, gender1, exposures. But there is 50 provinces and 2 genders. I will need a huge amount (120) of indexes:
banner_active, province1, gender1, exposures
banner_active, province2, gender1, exposures
banner_active, province3, gender1, exposures
banner_active, province4, gender1, exposures
... etc
banner_active, province1, gender2, exposures
banner_active, province2, gender2, exposures
banner_active, province3, gender2, exposures
banner_active, province4, gender2, exposures
I wanted to create a separate table banners_provinces where to insert all selected provinces and then the query could be like this:
$banner = mysqli_query($connection1,"SELECT select banner_id p, banner_image b, url b FROM banners_provinces p join banners b on p.select banner_id=b.id WHERE p.province='$visitor_province' order by p.exposures ASC limit 0,1") or die('Error');
but there is also e gender option and that's makes everything very complicated.
I am sorry for my English but I hope you can understand my problem. Can you give me any suggestions for database structure, and indexing?
Thanks.