I am trying to write an onclick function for a button on my website. Whenever that button is clicked a SQL query is executed and data will be fetched from the database. My requirement is to fetch the 2 records randomly every time the button is clicked, but I am getting the same output every time.
<input type="button" class="button" name="creat" id="bCreat" value="CREAT">
Onclick function
document.getElementById("bCreat").onclick = function creatBingo()
{
console.log("function clicked")
<?php
global $wpdb;
$result = $wpdb->get_results ( "SELECT * FROM bingo_tasks order by rand () limit 2" );
?>
document.getElementById("r0").innerHTML = '<?php echo $result[0]->task_name;?>';
document.getElementById("r1").innerHTML = '<?php echo $result[1]->task_name;?>';
}
I tried to flush the value of $result
by assigning it to 0
and null
, but still i am getting the same value.
Is there way to get different results everytime the button is clicked?