Re: Random query question

2011-05-20 Thread ShadowCross
If you are using MySQL as your database backend, read
http://www.desilva.biz/mysql/random.html  (found by Googling mysql
random row).

If you are not using MySQL, check if your database has a similar
function.

On May 19, 5:56 am, Sarpidon epap...@gmail.com wrote:
 Hi everybody.

 I have a companies table and those companies have promotions. Each
 company can have up to 10 promotions but only 2 can be displayed from
 each company at one time. I've been trying to figure out how to
 generate a single query that will select only 2 promotions randomly
 from each company. Is that even possible?

 see screenshot attached --http://screencast.com/t/dB2sqcEns

 so basically randomly select only 2 promotions with the same
 company_id...
 possible? how?

 Thank you for your time.

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: Random query question

2011-05-20 Thread Sarpidon
Thank you guys. Going through your suggestions now.

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Random query question

2011-05-19 Thread Sarpidon
Hi everybody.

I have a companies table and those companies have promotions. Each
company can have up to 10 promotions but only 2 can be displayed from
each company at one time. I've been trying to figure out how to
generate a single query that will select only 2 promotions randomly
from each company. Is that even possible?

see screenshot attached -- http://screencast.com/t/dB2sqcEns

so basically randomly select only 2 promotions with the same
company_id...
possible? how?

Thank you for your time.

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: Random query question

2011-05-19 Thread dreamingmind
one simple way would be to fetch all the records, then generate two
non-equal random numbers in the range of found records, then pluck
those two out of the result array. The returned records are numbered
0-10 in that array so it will be very simple to do!

http://us.php.net/manual/en/function.rand.php

Regards,
Don

On May 19, 5:56 am, Sarpidon epap...@gmail.com wrote:
 Hi everybody.

 I have a companies table and those companies have promotions. Each
 company can have up to 10 promotions but only 2 can be displayed from
 each company at one time. I've been trying to figure out how to
 generate a single query that will select only 2 promotions randomly
 from each company. Is that even possible?

 see screenshot attached --http://screencast.com/t/dB2sqcEns

 so basically randomly select only 2 promotions with the same
 company_id...
 possible? how?

 Thank you for your time.

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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