What are the potential pitfalls of having multiple tables in a database for different categories like pop, rock, and classic in PHP?
Having multiple tables for different categories like pop, rock, and classic can lead to data redundancy and inconsistency. To solve this issue, you can use a single table with a category column to store the category information for each record. This way, you can easily query and manage all categories in one place.
// Create a single table to store music records with a category column
CREATE TABLE music (
id INT AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(255),
artist VARCHAR(255),
category VARCHAR(50)
);
// Insert a record into the music table
INSERT INTO music (title, artist, category) VALUES ('Song Title', 'Artist Name', 'Pop');
// Query all pop songs from the music table
SELECT * FROM music WHERE category = 'Pop';