mardi 22 décembre 2015

Add random numbers in database

I have an array of 5 numbers. I am using event scheduling to insert rows after every 5 seconds, but it keeps on inserting the first value only. how can I insert different values of array at every insert in mysql.

Here is my code:

<?php
  require_once('con.php');  
  $numb = array(101,245,342,894,45);
  $random = array_rand($numb);
  for($a=0;$a<=5;$a++)
  {
        $query = "CREATE EVENT myEvent1 ON SCHEDULE EVERY 5 SECOND DO BEGIN INSERT INTO emp(emp_id) VAlUES('$numb[$random]'); END";
        $res = mysqli_query($con,$query);
  }
?>




Aucun commentaire:

Enregistrer un commentaire