hye im maya, i need to generate unique title like wordpress. if title hello-world is exist,the next title will be hello-world-2
thanks
hye im maya, i need to generate unique title like wordpress. if title hello-world is exist,the next title will be hello-world-2
thanks
Check the server to see if that title already exists
If it does, append a -2
and go to step 1. If you have already appended a -2
and the title already exists, replace it with a -3
, and so on.
If it doesn't, insert the file.
Example for step 1:
MySQL:
SELECT `title` FROM `table` WHERE `title` = '{$title}';
File (PHP):
$exists = file_exists("path/to/file");
Example for Step 2:
$iteration = 2;
while($exists){
$newname = $file . '-' . $iteration;
$iteration++;
// Check to see if the file exists here
}
else{
// Add the file here
}