Hello i am new to databases i know a bit about mysql but i am still learning and unable to create tables for my website . I have 10 main categories of images and then each main has further 3 sub categories . Please tell me how many databases and tables will i need for this? I am new to this stuff .
One table for the categories, one for the subcategories, and one to connect them all together: image name, category-id, sub-category-id(s)
You only need 1 database and I'd suggest you look for an existing script that does what you want. You'll learn faster by seeing what others do than by starting from scratch. At the bare minimum you need a category table with the following columns id int(11) primary key, auto increment parent_id(11) name then the image table id(11) primary key, auto increment category_id(11) name path source the columns you need will vary depending on how interactive you want the database to be. You might need a user_id, hell, you might need a whole user management and security setup.
Category table: id, category_name Sub-category table: id, sub_category_name Image-table: id, category_id, sub_category_id, image_name Now, if you want to add multiple sub_categories, you could do this differently, by adding a fourth table Image_subcategories id, image_id, sub_category_id And then repeat this for each subcategory you want that image to belong to - you would of course also remove the sub_category_id from the image table That way, the image-table will have a connection to the category table, and depending on your choice of one or multiple subcategories, a connection to the sub_category table This should be pretty straight forward to do via whatever MySQL-admin-software you have available - phpMyAdmin or similar.
thnx bro for such nice explanation, i am very new to all this , i will get deep into it . my head is woobling right now .
Just to clarify something about the image_subcategory table - and the line about repeating this - that was meant as "add one row for each image/subcategory", not a table pr image/subcategory, of course. It could be interpreted both ways, I saw.
If you're talking about the image-table, you can only have one primary key - and that will be the 'id'-column - you can index other columns depending on what you need, but mostly you'll just link tables with the corresponding IDs, so there isn't really that much need for that to begin with
You can do that, yes, if you want. They will then of course reference the primary IDs in the category-table and the sub_category-table.