PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
select * from questoes;
Copy Clear
Copy Format Clear
<?php $sql = "CREATE TABLE IF NOT EXISTS questoes ( id int NOT NULL AUTO_INCREMENT, pergunta varchar(255) NOT NULL, op1 varchar(255) NOT NULL, op2 varchar(255) NOT NULL, PRIMARY KEY (id) );"; if ($mysqli->query($sql) === TRUE) { echo "Tabela criada com sucesso\n"; } else { echo "Erro a criar a tabela: " . $conn->error ."\n"; } //$mysqli->query($sql); $sql_insert = "INSERT INTO questoes (pergunta,op1,op2) VALUES" . " ('pergunta1','opcao1','opcao2'),". "('pergunta2','opcaoa','opcaob'),". "('pergunta3','opcaoc','opcaod'),". "('pergunta4','opcaoe','opcaof'),". "('pergunta5','opcaog','opcaoh'),". "('pergunta6','opcaoi','opcaoj')"; $mysqli->query($sql_insert); //selecionar valor $sql = "SELECT COUNT(id) FROM questoes"; $max = intval($mysqli->query($sql)); srand(floor(time() / (60*60*24))); echo rand(); $aleatorio = rand(1, $max); $result = $mysqli->query("select * from questoes Where id = $aleatorio"); $row = $result -> fetch_assoc(); echo $row['id']."\n"; echo $row['pergunta']."\n"; echo $row['op1']."\n"; echo $row['op2']."\n"; //formulario //... echo "<h1>Questoes</h1>"; echo "<h1>Questoes</h1>" ;/*. "<p>".$row['pergunta']."</p>" . "<p>".$row['op1']."</p>" . "<p>".$row['op2']."</p>";*/ echo "<form action='' method='post'>"; echo '<input type="radio" id="op1" name="op" value="1">'; echo '<label for="op1">'.$row['op1'].'</label><br/>'; echo '<input type="radio" id="op2" name="op" value="2">'; echo '<label for="op2">'.$row['op2'].'</label><br/>'; echo '<button type="submit">Enviar</button>'; echo "</form>"; $result -> free_result(); $mysqli -> close(); ?>
Show:  
Copy Clear