title: Check existing data and Loop Back
body: <p>Hello so I have a code that will generate a random number and echo out "UNIQUE" if its not in the database. Here is my code:</p>
  
  <pre><code>$require 'connection.php';
  try {
      $generateID = mt_rand(100000, 999999);
      $checkRandomString = $conn-&gt;prepare("SELECT * FROM myTable WHERE generatedID = ?");
      $checkRandomString-&gt;execute(array($generateID));
      $row = $checkRandomString-&gt;fetch(PDO::FETCH_ASSOC);
      if($row &gt; 0) {
          // loop back and generate again until it echos out "UNIQUE"
      } else {
          echo "UNIQUE";
      }
  } catch {PDOException $e} {
      echo $e-&gt;getMessage();
  }
  </code></pre>
  
  <p>What I wanted to do is if the <code>$generatedID</code> is existing, I want it to automatically generate again until it echo's out <code>"UNIQUE"</code>. How can I do that?</p>