PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
CREATE TABLE banner ( id INT, name VARCHAR(20) ); INSERT INTO banner VALUES (1, 'Banner A'), (2, 'Banner B'), (3, 'Banner C');
Copy Clear
Copy Format Clear
<?php $sql = <<<SQL SELECT * FROM banner ORDER BY RAND() LIMIT ? SQL; $limit = 2; $result = $mysqli ->execute_query($sql, [$limit]) ->fetch_all(MYSQLI_ASSOC); while ( ($count = count($result)) < $limit && ($pool ??= $result) && shuffle($pool) ) { array_push( $result, ...array_slice($pool, 0, $limit - $count) ); } var_export($result);
Show:  
Copy Clear