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
Login    Share code      Blog   FAQ

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

Copy Format Clear
create table tickets ( fr_id int, user_id int ); insert into tickets values (1, 60), (2, 50), (3, 4), (4, 60), (5, 60), (6, 60), (7, 4), (8, 60), (9, 50), (10, 50);

Stuck with a problem? Got Error? Ask AI support!

Copy Clear
Copy Format Clear
<?php $user_id = 60; $query = "select sum(user_id = ?) / count(*) as chance from tickets;"; // get DB version using PDO $stmt = $pdo->prepare($query); $stmt->execute([$user_id]); $row = $stmt->fetch(PDO::FETCH_ASSOC); printf('Win chance for user %d is %s ' . PHP_EOL, $user_id, $row['chance']);
Copy Clear