Select count breaks in do-while loop <p>Where I work we need to register computers into a database, before we just used pen an paper, but I was asked to create an easier method. So I made a small local homepage.</p> <p>The computers are registered by a tag and number. The tag combined with the number must be unique, I made this loop that increment the entered number until it finds a free one.</p> <pre><code> $checkUnique = openConnection("stationer")-&gt;prepare("SELECT COUNT(1) FROM `dator` WHERE `tag_id`=:id AND `tag_number`=:number"); do{ $checkUnique -&gt; bindParam(":number", $_POST['number']); $checkUnique -&gt; bindParam(":id", $_POST['tag']); $checkUnique -&gt; execute(); $checkUniqueResult = $checkUnique-&gt;fetchColumn(); if($checkUniqueResult != 0 &amp;&amp; empty($searchTagNumber)){ $errors[] = "Non-unique tag and number"; break; } $_POST['number'] = $searchTagNumber == "+" ? $_POST['number']+1 : $_POST['number']-1; if($_POST['number'] &lt;= 0){ $errors[] = "The tag number can't be 0 or lower"; break; } }while($checkUniqueResult &gt; 0); </code></pre> <p>But for some odd reason, it appear to randomly stop, even if the tag and number isn't unique, with no error messages, and I have no idea what causes it.</p>