I want to make a query using which I can check that URL which I am making for a new video entry is not present in my db.
My current query is:
SELECT Count(videoid) FROM video WHERE titleurl = 'test';
I am storing count in a variable $n Then checking it using the following PHP code
if ($n > 0){
return $output . "-$n";
}else{
return $output;
}
But above query is creating a problem. Suppose
- 1st user submitted a video with name
Testso the url will behttp://example.com/video/test/ - 2nd user submitted a video with name
Testso the url will behttp://example.com/video/test-1/because one entry with titleurltestis already present, so I have added 1 in it which will betest-1 - 3rd user also added a video entry with name
testbut this time accoridng to my method url will betest-1which is wrong.
I want to solve this problem, if test is already present then it should be test-1 and if another user creating a entry with name test then url should be test-2 because test and test-1 are already there.
Please give some method with which I can solve this issue.