PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
create table IV_word ( id1 int (10) AUTO_INCREMENT, id2 int(10) NOT NULL, PRIMARY KEY (id1) ); INSERT INTO IV_word (id2) VALUES (3); INSERT INTO IV_word (id2) VALUES (1); INSERT INTO IV_word (id2) VALUES (2); INSERT INTO IV_word (id2) VALUES (6); INSERT INTO IV_word (id2) VALUES (6); INSERT INTO IV_word (id2) VALUES (6); INSERT INTO IV_word (id2) VALUES (6); SELECT * FROM IV_word;
Copy Clear
Copy Format Clear
<?php $sql = 'SELECT * FROM ( SELECT * FROM `IV_word` WHERE id2 = ? LIMIT 2 ) d ORDER BY RAND() LIMIT 1'; $chat_id = 6; $stmt = $mysqli->prepare($sql); $stmt->bind_param("i", $chat_id ); $stmt->execute(); $result = $stmt->get_result(); $row = $result->fetch_assoc(); var_export($row); $stmt->close();
Show:  
Copy Clear