PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
CREATE TABLE participants ( id bigint(20), name varchar(255), password varchar(255), product varchar(255), DOB date, points int(11), PRIMARY KEY(id) ); CREATE TABLE products ( id bigint(20), participant_id bigint(20), name varchar(255), quantity varchar(255), rate varchar(255), description varchar(255), FOREIGN KEY(participant_id) REFERENCES participants(id), PRIMARY KEY(id) );
Copy Clear
Copy Format Clear
<?php //connect to mysql database procedurally $conn = &$mysqli; //mysqli _connect("localhost","root","","anka"); $participantid = 0; $content = ''; //should return rank, points, products left(quantity) $sql1 = "SELECT points from participants where id='$content'"; $sql2 = "SELECT quantity from products where participant_id='$content'"; $sql3 = "WITH ranked AS( SELECT id, points, ROW_NUMBER() OVER( ORDER BY points ) RowNumber FROM participants ) SELECT * FROM ranked WHERE id='$content'"; $result1 = mysqli_query($conn, $sql1); $result2 = mysqli_query($conn, $sql2); $result3 = mysqli_query($conn, $sql3); while ($row1 = $result1->fetch_assoc()) { $points = $row1['points']; } while ($row2 = $result2->fetch_assoc()) { $quantity = $row2['quantity']; } while ($row3 = $result3->fetch_assoc()) { $rank = $row3['RowNumber']; }
Show:  
Copy Clear