Popeye Posted May 15, 2006 Share Posted May 15, 2006 Hi All, thanks for looking!I need an answer for this, please.In a sql table I add the name Guest + a number 0 -9so it would be Guest3 for example, or even just Guest.I need to sort the returned data so if, say, Guest 2 has left, that number can be reused?I have put a day into this one, and all I worked out is its harder than it looks.This gets Guestx but not Guest?eregi("(^Guest?)([0-9]?)", $value2, $msg);And then I cant think of a loop that will give the next available number?I had a few tries but none work reliably.Any Ideas?ThanksPopeye. Link to comment https://forums.phpfreaks.com/topic/9715-need-to-find-if-a-number-exists-in-a-range-seems-simple/ Share on other sites More sharing options...
trq Posted May 15, 2006 Share Posted May 15, 2006 I really think it would be much easier and more efficient if you re thought your database design. Id keep the number is a seperate column.Look into database normalization methods. Link to comment https://forums.phpfreaks.com/topic/9715-need-to-find-if-a-number-exists-in-a-range-seems-simple/#findComment-35965 Share on other sites More sharing options...
Popeye Posted May 15, 2006 Author Share Posted May 15, 2006 Thanks for the quick reply.I did think of adding a new table just to keep track off the Guests. But at the time I thought it seemed easier to use php?Then again we all know what thought did, hey :)The last time I messed with a xoops DB I broke it.Perhaps tomorrow I'll be thinking clearer.Popeye Link to comment https://forums.phpfreaks.com/topic/9715-need-to-find-if-a-number-exists-in-a-range-seems-simple/#findComment-35974 Share on other sites More sharing options...
Popeye Posted May 20, 2006 Author Share Posted May 20, 2006 Hi All.This is what I came up with:[code] $i = '1'; while($i <= ($num_of_rows )) { while(list( $name, $value) = mysql_fetch_row($result) ) { $value2 = $value; eregi("(^Guest?)([0-9]?[0-9]?)", $value, $msg); $newvalue .= $msg[2]." "; } $i = $i + 1; }; $newi = '0'; $newcount = ''; $newvalue =$newvalue; while($newi <= $num_of_rows) { if(eregi($newi,$newvalue )) { }else { $newcount .= $newi." "; } $newi++; } print "NewValue (Numbers used already) is ".$newvalue."<br>"; print("NEWCOUNT (Numbers left) ".$newcount."<BR>"); $newuser = explode(" ",$newcount, 3); print("NewUser is Guest".$newuser[0]);[/code]As I live in the "Bush" and teach myself, there is probably a better (neater) way to do this.I would welcome all "nit picking" and suggestions on whats wrong and how to improve it.RegardsPopeye Link to comment https://forums.phpfreaks.com/topic/9715-need-to-find-if-a-number-exists-in-a-range-seems-simple/#findComment-37334 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.