I am using MySQL to store ad information in the following table:

img_link varchar(50),
text text,
service varchar(50) default NULL,
title varchar(50) default NULL,
priority int(2) default '0',
status enum('current', 'old'),
ID int(3) NOT NULL auto_increment,

Ads for which advertisers pay more will have a higher priority - i.e. 1, 2, 3, etc. Everything else will have a priority of 0. When the page loads, I want to first display any ads that have a priority higher than 0 to be displayed in order, and then the remaining ads with a priority if 0 to be displayed in random order. They have to be displayed in a different order each time, so that each ad has the same chance of being displayed in a particular spot as any other ad. The only spots a random ad cannot be in is one taken by a higher paying ad. I hope this is clear.

Is it possible to do this with one query? Or would I have to use 2 different queries:

select * from ads_value where status = 'current' and priority > 0 order by priority asc

and then

select * from ads_value where status = 'current' and priority = 0 order by RAND()



PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to