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 // $mysqli is already declared as a working database connection by this sandbox $ids = [1, 5, 18, 25]; $count = count($ids); $bindString = str_repeat('s', count($ids)); $sql = 'SELECT name FROM somewhere WHERE id IN ($placeholders)'; $stmt=mysqli_stmt_init($conn); mysqli_stmt_prepare($stmt, $sql); mysqli_stmt_bind_param($stmt, $bindString, ...$placeholders); mysqli_stmt_execute($stmt); $empRecords=mysqli_stmt_get_result($stmt); $result=mysqli_num_rows($empRecords); if ($result > 0) { while ($row = mysqli_fetch_assoc($empRecords)) { $number=$row['a_number']; } echo $number; } else {
Show:  
Copy Clear