title: Insert random id into database
body: <p>I'm trying to insert records in my database and I am using this code:</p>
  
  <pre><code>&lt;?php 
  $con = mysql_connect('localhost','root','')
  or die(mysql_error());
  mysql_select_db ("my_db");
  
  $patient_array = array();
  
  $query = "SELECT * FROM accounts";
  $result = mysql_query($query);
  
  while($row = mysql_fetch_array($result))
  {
  $patient_array[$row['account_id']] = array("lastname" =&gt; $row['lastname'], 
  "firstname" =&gt; $row['firstname']);
  }
  
  foreach($time_table as $tid =&gt; $t){
  echo array_rand($patient_array, 1);
  echo $tid."====".$t["from"]." - " . $t["to"]."&lt;br /&gt;";
  
  $sql = "INSERT INTO appointment (appt_id, appt_date, appt_time, appt_doctor, 
  patient_id, appt_time_end) VALUES ('', '".$appt_date."', '".$t["from"]."', 
  '".$doc."', '".$tid."', '".$t["to"]."')";
  
  mysql_query($sql);
  }
  ?&gt; 
  </code></pre>
  
  <p>This one is properly inserting but for the "patient_id" I want to store random ids. $tid gives me random output but when I check the database, it's not the same; it's showing ids in descending order. I tried using Order by Rand() but I can't figure out how to make it working. Any idea? Or am I missing something?</p>
  
  <p>Thanks!</p>
  
  <p>EDIT: I am getting the patient_id from another table, which is the accounts table to be passed into appointment table. I was able to select random patient ids but how can I insert it to another table, in random order also.</p>