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
Share on other sites

making the field auto-incrementing will mean that whatever I put into it will automatically be post incremented?  How does that affect insertions?

Thanks Thorpe, you're saving my ass again.

Can a string be autoincremented? This is my Primary key.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.