hye im maya, i have to generate unique title like wordpress. if title hello-world is exist,the following title is going to be hello-world-2


  1. Look into the server to ascertain if that title already is available

  2. Whether it does, append a -2 and visit step one. For those who have already appended a -2 and also the title already is available, change it having a -3, and so forth.

  3. Whether it does not, place the file.

Example for step one:


SELECT `title` FROM `table` WHERE `title` = '{$title}';

File (PHP):

$exists = file_exists("path/to/file");

Example for Step Two:

$iteration = 2;

      $newname = $file . '-' . $iteration;
      // Check to see if the file exists here

    // Add the file here