Jump to content

query a list and close entires


djp1988

Recommended Posts

On this page: http://uk.eurosport.yahoo.com/football/fulham/ there is a snippet from the league football table with the featured team and the 2 clubs above and below it, how can I query to get a list and designate one of the lines to be the center with 2 above and 2 below in this way?Or is this 3 queries ?Maybe if I give you an exemple of what I want to apply this to, I have photo contributions to my site, and a profile page, I class these contributors so they want to be number 1, on the profile page I want t show the current position in the classification and the one before him and after him

Link to comment
Share on other sites

It's not necessarily a database query, I almost guarantee that those sports records aren't stored in the database in that order, they get calculated from data in the database. You need to way to build your list and figure out which position the item you want to show is at and figure out which items in the list you want to display. There's not much more to it than that, but I wouldn't be able to tell you how to build your list.

Link to comment
Share on other sites

Yes I've been working on it for hours, I got muddled up with numbers at one point, this has been one of the most annoying php scripts i have done, but the end result is what i wanted, thanks for your reply, I did the following:queried my list (with a colomn i had a COUNT and ordered by it), got the number of rows, used a while() to see if the row is what i wanted, incrementing a variable each time it looped, once it matched the row with what i wanted, i set some variables such as the position of the row thanks to the incrementing variable, then I queried using LIMIT $positionoftherow, 2 with if() and elseif() to change it to LIMIT...,1 or not query if the row was number one, and the same thing for the two lower entries... very interesting

Link to comment
Share on other sites

You only need the one query, if you already have the list you don't need to get it again, you just need to figure out which items to display. If you have variables for the total number of records, the position of the item you're looking for, and how many to show either before or after the item, that's all you need. Most of the logic you need is to make sure that the items to get before and after the target are still in the list (i.e., if the item is first you don't want to show any before it).

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...