PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
CREATE TABLE somewhere ( id INT AUTO_INCREMENT, name VARCHAR(100), PRIMARY KEY (id) ); INSERT INTO somewhere(id, name) VALUES (1, 'Chad'), (4, 'Ned'), (5, 'Dave'), (14, 'Newt'), (18, 'Bill'), (21, 'Norton'), (25, 'Alan');
Copy Clear
Copy Format Clear
<?php $ids = [1,2,3,4,5]; $stmt = $mysqli->prepare("SELECT * FROM somewhere WHERE id IN (" . rtrim(str_repeat('?,', count($ids)), ',') . ") ORDER BY id"); $stmt->execute($ids); $result = $stmt->get_result(); var_export($result->fetch_all(MYSQLI_ASSOC));
Show:  
Copy Clear