PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
CREATE TABLE `cart` ( `id` int primary key auto_increment, `user` int ); INSERT INTO `cart` (`user`) VALUES (1), (2), (3); CREATE TABLE `button` ( `id` int primary key auto_increment ); INSERT INTO `button` (`id`) VALUES (4);
Copy Clear
Copy Format Clear
<?php $user = 1; $result = mysqli_query($mysqli, "SELECT * FROM `cart` LEFT JOIN `button` ON cart.id = button.id UNION ALL SELECT * FROM `cart` RIGHT JOIN `button` ON cart.id = button.id WHERE `user`='" . $user . "'"); while($row = mysqli_fetch_assoc($result)) { print_r($row); }
Show:  
Copy Clear