Hi! Could we please enable some services and cookies to improve your experience and our website?

PHPize Online / SQLize Online  /  SQLtest Online

A A A
Login    Share code      Blog   FAQ

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

Copy Format Clear
create table products ( id int primary key auto_increment, product varchar(64), color varchar(16) ); insert into products(product, color) values ('t-shirt', 'red'), ('sweater', 'blue'), ('t-shirt', 'green'), ('sweater', 'yellow'), ('t-shirt', 'purple'), ('sweater', 'indigo'), ('t-shirt', 'black');

Stuck with a problem? Got Error? Ask AI support!

Copy Clear
Copy Format Clear
<?php $product = 'sweater'; $query = "select distinct color from products where product = ?;"; // get DB version using PDO $stmt = $pdo->prepare($query); $stmt->execute([$product]); $colors = $stmt->fetchAll(PDO::FETCH_ASSOC); print_r($colors);
Copy Clear