How do you select 3 adjacent rows with emphasis on the lower values in MySQL?

I’m trying to figure out how to select 3 adjacent rows from a table with a price < current item price. The problem is that if I’m selecting the first, second, or third row in the table, I need to select three adjacent rows around the current item. Emphasis needs to be put on the lower price items, for example, if I’m selecting the third row from the table, I need to select the first two rows and the fourth row. Here is my query so far:

SELECT * 
FROM (SELECT * 
      FROM temp_db_cart 
      WHERE airport='$airport' 
        AND people='$people' 
        AND price < '$price' 
      ORDER BY price DESC LIMIT 3
     ) 
ORDER BY price ASC LIMIT 3

PHP/MySQL combination can be used for an answer. Any help would be appreciated.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s