Jump to content

While() control structure help


kr3m3r

Recommended Posts

Hi guys, I've been working on this for too long, and am probably missing something obvious.  I'm trying to insert a unique UserID into my database.  To do this I'm using the substring to get the first letter of the first name, then substring to get the first 8 letters of the last name, and then I want to append the concatenated string with 1, or if that is taken, the next hightest available number.  But I'm having a heck of a time getting it to work.  I had it working at one point for a single name, but it wouldn't deal with duplicate names, I'm pretty mixed up as to why it doesn't work now.

 

The code is:

 

$TestUUserID = (substr($UFName,0,1).substr($ULName,0,."1");
$query = "select * from User where UserID = ".$TestUUserID;
$result = mysql_query($query);

if (!$result)
{
$i=2;
while(!$result && $i<9)
{
$TestUUserID = (substr($UFName,0,1).substr($ULName,0,.$i);
$query = "select * from User where UserID = ".$TestUUserID;
$result = mysql_query($query);
$i=$i+1;
}
}

if ($result)
{
echo 'Sorry, at this time, there are too many with that name combination.';
exit;
}

 

Thanks for your time and help, I really appreciate it.

-Robb

Link to comment
https://forums.phpfreaks.com/topic/66101-while-control-structure-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.