How would one go about generating a not-used post slug?
<p>I have a website with a URL like: <a href="http://mysite.com/this-is-a-page" rel="nofollow">http://mysite.com/this-is-a-page</a> and then I use that URL slug to get data from the database, however, if another page with the same exact slug exists, it will only display the one that resulted first and 9 times out of 10, it's not the correct one. I know I could just pass an ID to the slug, so the URL would be like: <a href="http://mysite.com/183/this-is-a-page" rel="nofollow">http://mysite.com/183/this-is-a-page</a> but I know that there must be a way to loop trough the results before submitting a page and then adding a INT to end, "this-is-page1", "this-is-page2" and so on. </p>

<p>My question is, how do I loop trough it and generate a valid slug? By theory, I would do something like the following:</p>

<pre><code>while($row = $result-&gt;fetch_object(){
   if($post_slug === $row-&gt;post_slug){
       $post_slug = $post_slug + 1;
   }
}
</code></pre>

<p>But I'm pretty sure some of you know how to do this better and I'm all for learning the best practices. All help is appreciated.</p>
