Jump to content

need to find if a number exists in a range, seems simple?


Popeye

Recommended Posts

Hi All, thanks for looking!

I need an answer for this, please.

In a sql table I add the name Guest + a number 0 -9
so 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?

Thanks
Popeye.
Link to comment
Share on other sites

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

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.

Regards
Popeye

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.