What potential pitfalls can arise from not normalizing database tables, especially when dealing with category assignments in PHP?
Not normalizing database tables can lead to data redundancy and inconsistency, making it difficult to update or query the database accurately. When dealing with category assignments in PHP, this can result in duplicate categories, incorrect category assignments, and inefficient queries. To solve this issue, it is important to normalize the database tables by creating separate tables for categories and properly linking them to the main table using foreign keys.
// Example of normalizing database tables for category assignments in PHP
// Category table
CREATE TABLE categories (
id INT PRIMARY KEY,
name VARCHAR(50)
);
// Main table with category assignments
CREATE TABLE items (
id INT PRIMARY KEY,
name VARCHAR(50),
category_id INT,
FOREIGN KEY (category_id) REFERENCES categories(id)
);