Forum Moderators: open

Message Too Old, No Replies

Help writing this tricky MySQL Query!

         

smagdy

10:14 pm on Jul 1, 2007 (gmt 0)

10+ Year Member



Hello!

I hope someone can help me write this query (MySQL 5)

- I get dynamic value, lets say now its number (5)

then i make a query that will bring me some numbers with this exact order, lets say
(100, 4, 32, 2, 12, 5, 34, 89, 101)

So how can i modify this query so it brings me just one number b4 & one number after my dynamic value which is 5 in this example!

In other words i just want this query to bring me (12, 5, 34)

SELECT id from ads where MATCH (title,desc) AGAINST ('word' IN BOOLEAN MODE) order by date

I know i can get all the values and filter it by PHP, but hope there is a way with SQL to filter the results, but i think its somehow not possible to tell SQL plz save the result starting from the number b4 my dynamic value!

Any inputs are appreciated!

Thanks in advance

smagdy

4:43 pm on Jul 3, 2007 (gmt 0)

10+ Year Member



Anybody?

coopster

8:24 pm on Jul 3, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I don't understand how the data is sitting in the table prior to the query execution?

smagdy

9:04 pm on Jul 3, 2007 (gmt 0)

10+ Year Member



Well....

Table "ads"
ad_id - title - txt
1 - title1 - txt1
22 - title22 - txt22
43 - ...........
15 - ............
29 - ............
3 - ...............
91 - ...............
88 - .............
73 -.............
etc..
.

then a query will bring up for ex these ad_ids 22 - 29 - 88 - 91 - 3
and ive specific id for ex. 91
so i want my select query to select just the id that is b4 & after this id
so if the id i ve is 91 and my search query would normally bring 22 - 29 - 88 - 91 - 3
then instead of that result, i just want to get 88 - 91 - 3

is it clear now?

FalseDawn

11:23 pm on Jul 3, 2007 (gmt 0)

10+ Year Member



I don't think there's any way to do it in SQL (at least in one statement) - you could do it by copying the data to a temporary table with an autoincrement field (ID), retrieving the ID value of the value you are after (x) and then retrieving the records with IDs x-1, x, x+1, but really, your best best is to retrieve them all into an array or something and do it procedurally.

[edited by: FalseDawn at 11:24 pm (utc) on July 3, 2007]

smagdy

12:24 am on Jul 4, 2007 (gmt 0)

10+ Year Member



Thanks... the problem is that these IDs could be thousands, so it will be slow to add them into table or array.... i was hoping to use the LIMIT to reach what i want....