# Ink Cartridge Search Website

A PHP and MySQL-based website for searching ink cartridges for printers.

## Features

- Search by cartridge model or printer model
- Filter by brand, color, and price range
- View cartridge details including compatibility, price, and stock
- Responsive design
- Real-time search results
- Optimized MySQL database with indexes

## Requirements

- PHP 7.4 or higher (with mysqli extension)
- MySQL 5.7 or higher / MariaDB 10.2 or higher
- Any web browser
- Apache/Nginx web server (or PHP built-in server for development)

## Installation

### Quick Start (Using XAMPP - Recommended for Beginners)

1. **Install XAMPP** (includes PHP, MySQL, and Apache)
   - Download from: https://www.apachefriends.org/
   - Install and start Apache and MySQL services

2. **Copy the project folder**
   - Copy `ink-cartridge-search` to `C:\xampp\htdocs\` (Windows)
   - Or to `/Applications/XAMPP/htdocs/` (Mac)
   - Or to `/opt/lampp/htdocs/` (Linux)

3. **Configure database** (if needed)
   - Open `config.php` and update credentials if your MySQL has a password
   - Default settings work with XAMPP out of the box

4. **Initialize the database**
   - Visit: `http://localhost/ink-cartridge-search/setup_database.php`
   - Wait for confirmation message

5. **Start searching!**
   - Visit: `http://localhost/ink-cartridge-search/`

### Alternative: Using PHP Built-in Server (Advanced)

1. **Ensure MySQL is running** on your system

2. **Start the PHP server**
   ```bash
   cd ink-cartridge-search
   php -S localhost:8000
   ```

3. **Initialize database**: Visit `http://localhost:8000/setup_database.php`

4. **Access app**: Visit `http://localhost:8000`

## Database Structure

**Database Name:** `ink_cartridge_db`

### ink_cartridges table
- `id` - INT, Primary key, Auto-increment
- `cartridge_model` - VARCHAR(100), Model number
- `brand` - VARCHAR(100), Manufacturer (HP, Canon, Epson, Brother)
- `color` - VARCHAR(50), Ink color (Black, Cyan, Magenta, Yellow, Tri-color, Color)
- `type` - VARCHAR(50), Cartridge type (Inkjet)
- `compatible_printers` - TEXT, Compatible printer models
- `price` - DECIMAL(10, 2), Price in USD
- `stock_quantity` - INT, Available quantity
- `page_yield` - INT, Estimated page yield
- `created_at` - TIMESTAMP, Record creation time

**Indexes:**
- `idx_brand` on `brand` column
- `idx_color` on `color` column
- `idx_price` on `price` column

**Character Set:** UTF8MB4 with utf8mb4_unicode_ci collation

The database is created automatically when you run `setup_database.php` and includes 21 sample cartridges.

## Usage

1. **Search**: Enter a cartridge model or printer model in the search box
2. **Filter**: Use the dropdown filters to narrow results by brand and color
3. **Price Range**: Set minimum and maximum price filters
4. **Clear**: Click "Clear Filters" to reset all filters

## Configuration

### Database Settings

Edit `config.php` to configure your MySQL connection:

```php
define('DB_HOST', 'localhost');     // MySQL host
define('DB_USER', 'root');          // MySQL username
define('DB_PASS', '');              // MySQL password
define('DB_NAME', 'ink_cartridge_db'); // Database name
```

### Adding More Cartridges

You can add cartridges directly through MySQL:

```sql
INSERT INTO ink_cartridges (cartridge_model, brand, color, type, compatible_printers, price, stock_quantity, page_yield)
VALUES ('HP 64XL', 'HP', 'Black', 'Inkjet', 'HP ENVY Photo 6200, 7100', 29.99, 15, 600);
```

Or modify the `$cartridges` array in `setup_database.php` before first run.

## Customization

- Edit `css/style.css` to customize the appearance
- Modify `setup_database.php` to add more sample cartridges
- Update filter options in the database to add new brands or colors
- Optimize database queries by adjusting indexes in the table creation SQL
