kr3m3r Posted August 22, 2007 Share Posted August 22, 2007 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 More sharing options...
trq Posted August 22, 2007 Share Posted August 22, 2007 I'm trying to insert a unique UserID into my database. Don't bother. Let your database do the work and use an auto incrementing field. Link to comment https://forums.phpfreaks.com/topic/66101-while-control-structure-help/#findComment-330605 Share on other sites More sharing options...
kr3m3r Posted August 22, 2007 Author Share Posted August 22, 2007 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 https://forums.phpfreaks.com/topic/66101-while-control-structure-help/#findComment-330608 Share on other sites More sharing options...
trq Posted August 22, 2007 Share Posted August 22, 2007 Can a string be autoincremented? You cannot increment a string, that makes no sense. Link to comment https://forums.phpfreaks.com/topic/66101-while-control-structure-help/#findComment-330615 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.