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
Share      Blog   Popular

PHPize.online is a free online environment for quickly running, experimenting with and sharing PHP (including Carbon extension for DateTime) and SQL code. You can run your SQL code with PHP code that can use the same DB. For database manipulations you can use pre-defined instances of PDO ($pdo), mysqli ($mysqli) & Laravel query builder ($db)

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 = 8; $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( array_combine( substr_replace( range(1, $count), 'banner_image_', 0, 0 ), $result ) );
Show:  
Copy Clear