title: Give another random int if number exists in database (PHP)
body: <p>I am trying to make a script to check if an int is already added to my database. If so, it will re-generate another random number and check again. If it doesn't exist, it'll insert into the database. </p>
  
  <p>However, I am having troubles. If a number exists, it just prints out <em>num</em> exists, how would I re-loop it to check for another and then insert that? I have tried to use <strong>continue;</strong>, <strong>return true;</strong> and so on... Anyway, here is my code; hopefully someone can help me!</p>
  
  <pre><code>&lt;?php
  require_once("./inc/config.php");
  
  $mynum = 1; // Note I am purposely setting this to one, so it will always turn true so the do {} while will be initiated.
  
  echo "attempts: ---- ";
  
  $check = $db-&gt;query("SELECT * FROM test WHERE num = $mynum")or die($db-&gt;error);
  
  if($check-&gt;num_rows &gt;= 1) {
      do {
  
          $newnum = rand(1, 5);
              $newcheck = $db-&gt;query("SELECT * FROM test WHERE num = $newnum")or die($db-&gt;error);
                  if($newcheck-&gt;num_rows &gt;= 1) {
                  echo $newnum . " exists! \n";
                  } else {
              $db-&gt;query("INSERT test (num) VALUES ('$newnum')")or die($db-&gt;error);
              echo "$newnum - CAN INSERT@!@!@";
              break;
          }
  
      } while(0);
  }
  ?&gt;
  </code></pre>