Here's my PHP code - it checks to see if a username exists and if it does it adds a "_" and an ascending number to it.
$username
starts as a user entered Username.
$usernameCopy = $username;
$appendNum = 1;
$userOK = false;
while( $userOK == false )
{
$query = "SELECT ua.id
FROM someDB.users_accounts ua
WHERE ua.user = '$username'; ";
$resultID = mysqli_query($linkID, $query) or die("Data not found. USERNAME");
$numRows = mysqli_num_rows($resultID);
if( $numRows <> 0)
{
//USER ALREADY EXISTS
$appendNum = $appendNum + 1;
$username = $usernameCopy . '_' . $appendNum;
}
else
{
$userOK = true;
}
}
Then I use the $username
.
Is it possible to do something like this is a single SQL query?