Jump to content

Archived

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

Popeye

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

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

×

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.