nabil you are right...i realized it too and returned a string "taken"
or "free"...it works now...... i am saying:
$eyed = $this->find(array('eyed' => $data), array('eyed'));
if(empty($eyed) == true){
return "free";
}else{
return "taken";
and in my controller
do{
$lkbl_eyed=rand(1,5);
}
while ($eyed = $this->Linkable->validateEyed($lkbl_eyed) ==
"taken");
return $lkbl_eyed;
}
now its fine....but an endless loop is created when all numbers are
taken.....he is not ending the loop then...any idea how i can cake to
take a break if all numbers are taken?
thx
On 11 Aug., 17:28, Nabil Alsharif <[email protected]> wrote:
> On Wed, Aug 11, 2010 at 4:18 AM, Tomfox Wiranata
>
>
>
> <[email protected]> wrote:
> > ok i tried your solution and somehow cake does not care if it writes
> > the same number over and over in my database. maybe you see what's
> > wrong here :)
>
> > my function in my model "abc" that finds and compares the number. my
> > logic: when no entry is found here $eyed is empty.
>
> > function validateEyed($data)
> > {
> > $eyed = $this->find(array('eyed' => $data), array('eyed'));
> > if(empty($eyed) == true)
> > return $eyed['abc'];
> > return false;
> > }
>
> This part is trippin me up... You are checking that $eyed is empty and
> if it is you are returning an element from it? Is that right or are my
> eyes just seeing thigs?
>
>
>
> > I am calling this function from my controller
>
> > function __createEyed()
> > {
>
> > do{
> > $test=rand(1,2);
> > }
> > while ($eyed = $this->abc->validateEyed($test) == true);
> > return $test;
> > }
>
> > cakes writes those rand numbers "1" or "2" multiple times in my table.
> > so where is the mistake??
>
> > thx :)
>
> > On 10 Aug., 18:39, cricket <[email protected]> wrote:
> >> On Tue, Aug 10, 2010 at 12:30 PM, Tomfox Wiranata
>
> >> <[email protected]> wrote:
> >> > thx to both..
> >> > :)
>
> >> > @cricket:
>
> >> > am i getting it right? you are writing all numers from the database
> >> > into an array and compare both? is it possible that at a certain point
> >> > it will get to big or too much data? cause my range starts at
> >> > 111111111 and ends at 999999999
>
> >> > if there are 50million in the table they all get saved in an array....
>
> >> Yes, that's correct. I should have pointed that out. You could cache
> >> the results, of course, but perhaps a better way would be to pass
> >> $new_number to a protected method (that does a find() and comparison)
> >> inside the while section. You'd have to have the separate method
> >> because while() isn't a block, where you can have several lines of
> >> code. Something like:
>
> >> public function getNewNumber()
> >> {
> >> do
> >> {
> >> $new_number = rand(10,100000);
> >> }
> >> while ($this->_testNewNumber($new_number));
>
> >> return $new_number;
>
> >> }
>
> >> protected function _testNewNumber($x)
> >> {
> >> // return $x exists in DB
>
> >> }
>
> > 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 [email protected]
> > To unsubscribe from this group, send email to
> > [email protected] 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 [email protected]
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en