it shows my first copy of 
Copy (1) of You in 10 Years
This is my solution
PHP Code:
// Finds next# to enter the survey "Copy of (#) $title"
function next_copy_num($title)
{
// strips "copy (#) of " from the title
$_SESSION['title'] = $regex_title = eregi_replace('^(copy \()[0-9]*\) of ',null,$title);
$SQL = 'SELECT title, title regexp "^(copy \\\()[0-9]*(\\\) of '.$regex_title.')$" as regex
FROM survey
WHERE rel_uid = '.$_SESSION['user'].'
HAVING regex > 0';
$result = mysql_query($SQL);
// retrieves all survey titles that match the pattern: copy (#) of $title
$count = 0;
while ($sql_assoc = mysql_fetch_assoc($result))
{
$count++;
$db_title[$count] = $sql_assoc['title'];
}
// finds the largest # of all the retrieved titles
while ($count) // uses $count from the mysql_fetch
{
// doesn't allow user to make more than 99 duplicates
if ((int) substr($db_title[$count],6,2) == 99)
return 0;
if ((int) substr($db_title[$count],6,2) > $num)
{
$num = (int) substr($db_title[$count],6,2);
}
$count--;
}
return $num+1;
}
Bookmarks