Use the right data type. If you are concerned about the numbers running out use 
an unsigned bigint; that goes to 1,8446,744,073,709,551,615. Would that be 
enough for you? ;-)

http://dev.mysql.com/doc/refman/5.0/en/numeric-types.html

Jeremy Burns
Class Outfit

jeremybu...@classoutfit.com
http://www.classoutfit.com

On 13 Aug 2010, at 10:24, Tomfox Wiranata wrote:

> only one....what if all numbers are used? it might take a while but
> the time will come
> 
> On 13 Aug., 11:09, Jeremy Burns | Class Outfit
> <jeremybu...@classoutfit.com> wrote:
>> I don't know the rest of your set up, but auto increment would seem like a 
>> really simple solution. It wouldn't need any programming either, which must 
>> be a good thing.
>> 
>> You mention re-using numbers - I would guess that re-using a number that 
>> previously identified a completely different (and potentially obsolete) 
>> product is a bad thing.
>> 
>> On balance, I would say that letting the database assign a new, unique and 
>> automatically generated number each time you create a product sounds like 
>> the right thing to do - unless there is some rock solid reason why this 
>> would break something else.
>> 
>> Jeremy Burns
>> Class Outfit
>> 
>> jeremybu...@classoutfit.comhttp://www.classoutfit.com
>> 
>> On 13 Aug 2010, at 10:04, Tomfox Wiranata wrote:
>> 
>>> so you would suggest auto_increment?
>> 
>>> On 13 Aug., 10:48, Jeremy Burns | Class Outfit
>>> <jeremybu...@classoutfit.com> wrote:
>>>> The number will rise by 1 on each insert (or attempted insert that fails 
>>>> validation at the database level) and once a number has been used it is no 
>>>> longer available (although it is possible to do a direct insert using SQL, 
>>>> but not really recommended). It isn't really possible to reserve numbers 
>>>> ahead of time without doing lots of fancy stuff.
>> 
>>>> Reading this whole trail it seems that you are using a sledgehammer to 
>>>> crack a nut. I'd keep it simple and let the database do what it was born 
>>>> to do.
>> 
>>>> Jeremy Burns
>>>> Class Outfit
>> 
>>>> jeremybu...@classoutfit.comhttp://www.classoutfit.com
>> 
>>>> On 13 Aug 2010, at 09:42, Tomfox Wiranata wrote:
>> 
>>>>> i was under the impression, that it makes trouble, when a product will
>>>>> be deleted and the number is free again. will this number then be
>>>>> skipped cause auto increment passed it a long time ago?
>> 
>>>>> also i want specific numbers to be reserved. so these ones should be
>>>>> left out when auto incrementing...
>> 
>>>>> if those 2 thing wont bother then it would be fine, i guess.
>> 
>>>>> On 13 Aug., 09:46, Jeremy Burns | Class Outfit
>>>>> <jeremybu...@classoutfit.com> wrote:
>>>>>> What's so wrong with using the (auto incrementing unique) id field then?
>> 
>>>>>> Jeremy Burns
>>>>>> Class Outfit
>> 
>>>>>> jeremybu...@classoutfit.comhttp://www.classoutfit.com
>> 
>>>>>> On 13 Aug 2010, at 08:39, Tomfox Wiranata wrote:
>> 
>>>>>>> hey sam, thx. the number is sth like a product code. each product will
>>>>>>> be assigned with a unique number...
>> 
>>>>>>> seems like an alternative, since i am too stupid to make it with do
>>>>>>> while^^
>> 
>>>>>>> On 13 Aug., 05:22, Sam <s...@masterscommission360.com> wrote:
>>>>>>>> Also- I just had an idea... it is kind of janky but I think it will do
>>>>>>>> what you want with a good speed increase.
>> 
>>>>>>>> When you get your random number, check if it is already in the
>>>>>>>> database by doing the following:
>>>>>>>>         $count = $this->find(
>>>>>>>>                 'count',
>>>>>>>>                 array(
>>>>>>>>                         'conditions' => array(
>>>>>>>>                                 'Linkable.number' => $randomNumber
>>>>>>>>                         )
>>>>>>>>                 )
>>>>>>>>         );
>> 
>>>>>>>> If $count is not 0 then the number already exists in the database- now
>>>>>>>> instead of getting all the db values and looping a bunch of times,
>>>>>>>> generate 10 random numbers and put them in an array and do the
>>>>>>>> following
>> 
>>>>>>>>         $linkNumbers = $this->find(
>>>>>>>>                 'list',
>>>>>>>>                 array(
>>>>>>>>                         'conditions' => array(
>>>>>>>>                                 'Linkable.number' =>
>>>>>>>> $randomNumberArray
>>>>>>>>                         )
>>>>>>>>                 )
>>>>>>>>         );
>> 
>>>>>>>> Count the elements in the returned array(count($linkNumbers))- if it
>>>>>>>> is less then 10 then at least one of the random numbers you generated
>>>>>>>> is not yet in the database- use array_diff to find out which values
>>>>>>>> are not in the database and you will be left with an array of good
>>>>>>>> random numbers to use:
>>>>>>>> $unusedRandomNumbers = array_diff($linkNumbers, $randomNumberArray)
>> 
>>>>>>>> If the $linkNumbers array has 10 elements then just repeat the
>>>>>>>> process.
>> 
>>>>>>>> On Aug 12, 7:41 pm, Sam <s...@masterscommission360.com> wrote:
>> 
>>>>>>>>> Can you tell us what you are using this random number for? This might
>>>>>>>>> be a situation where there is an alternative solution that we could
>>>>>>>>> help you out with if we knew why you needed the random numbers. Also-
>>>>>>>>> on the topic of uuid's, aren't they just a hexadecimal number?
>>>>>>>>> Couldn't you just convert them to decimal as needed?
>> 
>>>>>>>>> On Aug 12, 3:10 am, Tomfox Wiranata <tomfox.wiran...@gmail.com> wrote:
>> 
>>>>>>>>>> thx to both of you. i know i always do things complicated...
>> 
>>>>>>>>>> so if i do what you suggested, cricket:
>> 
>>>>>>>>>> public function getNewNumber()
>>>>>>>>>> {
>>>>>>>>>>         do
>>>>>>>>>>         {
>>>>>>>>>>                 $new_number = rand(10,100000);
>>>>>>>>>>         }
>>>>>>>>>>         while ($this->_testNewNumber($new_number));
>> 
>>>>>>>>>>         return $new_number;
>> 
>>>>>>>>>> }
>> 
>>>>>>>>>> i'm having an endless loop :(
>> 
>>>>>>>>>> how would my function look like, that is checking for existence? cant
>>>>>>>>>> believe i am having so much trouble with this....
>> 
>>>>>>>>>> On 12 Aug., 03:35, cricket <zijn.digi...@gmail.com> wrote:
>> 
>>>>>>>>>>> On Wed, Aug 11, 2010 at 4:45 PM, McBuck DGAF <mcbuckd...@gmail.com> 
>>>>>>>>>>> wrote:
>>>>>>>>>>>> This whole process strikes me as very inefficient.  There is no
>>>>>>>>>>>> mechanism to prevent your do-while loop from checking the same 
>>>>>>>>>>>> value
>>>>>>>>>>>> an infinite number of times (unless you log each random value and
>>>>>>>>>>>> check the next random value against the log AND the db).
>> 
>>>>>>>>>>>> I don't know what the purpose of the random value is in your app, 
>>>>>>>>>>>> but
>>>>>>>>>>>> I would suggest an entirely different approach.  If you need random
>>>>>>>>>>>> values in the range of "min" through "max," you could generate a 
>>>>>>>>>>>> table
>>>>>>>>>>>> ahead of time consisting of the fields id and random_number, with 
>>>>>>>>>>>> max-
>>>>>>>>>>>> min+1 rows.  (There are many random number generator sites 
>>>>>>>>>>>> available,
>>>>>>>>>>>> and you might be able to access one of their APIs as needed.)
>> 
>>>>>>>>>>>> It seems to me that it would be easier to generate these unique 
>>>>>>>>>>>> values
>>>>>>>>>>>> in some random order ahead of time, and then just associate the
>>>>>>>>>>>> random_numbers table with your current table through a 1-1
>>>>>>>>>>>> relationship.  This process would make it easy to identify the next
>>>>>>>>>>>> random number to be assigned, and when the random numbers have been
>>>>>>>>>>>> exhausted.
>> 
>>>>>>>>>>>> Just a thought.
>> 
>>>>>>>>>>> What McBuck said. I've given you a solution but you're implementing 
>>>>>>>>>>> it
>>>>>>>>>>> in a very strange way. FWIW, this:
>> 
>>>>>>>>>>> while ($eyed = $this->Linkable->validateEyed($lkbl_eyed) ==
>>>>>>>>>>> "taken");
>> 
>>>>>>>>>>> is always going to return true. Why are you assigning a value to
>>>>>>>>>>> $eyed, which is never used, in any case? That assignment is what is
>>>>>>>>>>> screwing things up.
>> 
>>>>>>> Check out the new CakePHP Questions sitehttp://cakeqs.organdhelpothers 
>>>>>>> with their CakePHP related questions.
>> 
>>>>>>> You received this message because you are subscribed to the Google 
>>>>>>> Groups "CakePHP" group.
>>>>>>> To post to this group, send email to cake-php@googlegroups.com
>>>>>>> To unsubscribe from this group, send email to
>>>>>>> cake-php+unsubscr...@googlegroups.com For more options, visit this 
>>>>>>> group athttp://groups.google.com/group/cake-php?hl=en
>> 
>>>>> Check out the new CakePHP Questions sitehttp://cakeqs.organdhelp others 
>>>>> with their CakePHP related questions.
>> 
>>>>> You received this message because you are subscribed to the Google Groups 
>>>>> "CakePHP" group.
>>>>> To post to this group, send email to cake-php@googlegroups.com
>>>>> To unsubscribe from this group, send email to
>>>>> cake-php+unsubscr...@googlegroups.com For more options, visit this group 
>>>>> athttp://groups.google.com/group/cake-php?hl=en
>> 
>>> Check out the new CakePHP Questions sitehttp://cakeqs.organd help others 
>>> with their CakePHP related questions.
>> 
>>> You received this message because you are subscribed to the Google Groups 
>>> "CakePHP" group.
>>> To post to this group, send email to cake-php@googlegroups.com
>>> To unsubscribe from this group, send email to
>>> cake-php+unsubscr...@googlegroups.com For more options, visit this group 
>>> athttp://groups.google.com/group/cake-php?hl=en
> 
> Check out the new CakePHP Questions site http://cakeqs.org and help others 
> with their CakePHP related questions.
> 
> You received this message because you are subscribed to the Google Groups 
> "CakePHP" group.
> To post to this group, send email to cake-php@googlegroups.com
> To unsubscribe from this group, send email to
> cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
> http://groups.google.com/group/cake-php?hl=en

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

Reply via email to