Click to See Complete Forum and Search --> : help in sorting photos


jasongr
07-16-2006, 09:07 AM
Hi

I have the following table:

CREATE TABLE `image_info` (
`Image_ID` int unsigned not null auto_increment,
`Width` int unsigned not null,
`Height` int unsigned not null,
PRIMARY KEY (`Image_ID`),
) ENGINE=MyISAM DEFAULT CHARSET=latin1;


I would like to run a query that will return the first 10 random images. However, I would like to give preferences to horizontal images (i.e: width > height)

does anyone know how this can be achieved?

something like:

select *
from image_info
order by rand(), (width - height)
limit 0, 10;


any ideas?

aussie girl
07-16-2006, 09:19 AM
Have you tried that? You could also try..
select *
from image_info
WHERE width > height
order by rand()
limit 0, 10;

jasongr
07-16-2006, 09:31 AM
this is not want I want
this will only return horizontal images

I only want to give preferences to horizontal images
This means that if all the photos are vertical, then I will get vertical photos
However, if some of the photos are horizontal (width > height), then I want to get
them first before I get vertical ones

If I have 2 horizontal photos
1) width = 1000, height = 500
2) width = 1000, height = 800
Then I want to get 1) before 2) as 1 is "more" horizontal

but both should be returned

regards

aussie girl
07-16-2006, 11:18 AM
What about...

select *
from image_info
order by height, rand()
limit 0, 10;

How are you going to get different ones, I'm sure that simply using rand() doesn't guarantee that, you may have to use DISTINCT in your SELECT statement somewhere