Jump to content


Photo

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


  • Please log in to reply
3 replies to this topic

#1 Popeye

Popeye
  • New Members
  • Pip
  • Newbie
  • 3 posts
  • LocationBombala Australia

Posted 15 May 2006 - 02:34 PM

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.

#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 15 May 2006 - 02:37 PM

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.

#3 Popeye

Popeye
  • New Members
  • Pip
  • Newbie
  • 3 posts
  • LocationBombala Australia

Posted 15 May 2006 - 02:54 PM

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

#4 Popeye

Popeye
  • New Members
  • Pip
  • Newbie
  • 3 posts
  • LocationBombala Australia

Posted 20 May 2006 - 12:47 AM

Hi All.

This is what I came up with:

        $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]);


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






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users