Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find page number based on id

Status
Not open for further replies.

rogerood

Programmer
Oct 27, 2005
13
GB
Hi, i'm running php with mysql and i have a reviews section on my website. I've recently added the feature to search the reviews but my trouble lies that I don't have a seperate page for each review I have them on multiple pages (like a forum). What I need to do is pass the review id on the search page to the review page (reviews.php) and retrieve the current page the review is on (15 reviews per page order by date desc). I've been trying to do this for the last couple of days but it's finally beaten me.

Here's the structure of the reviews table to give you a hand:
- id
- title
- content
- date

I'd appreciate if someone could help. Thanks
 
It's seems to me your reviews are stored in your DB correct?
Why don't you just autoput the review when it finds it on the DB.

So when your search gets a hit, you get the review it found and output the content field onto the page.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Hi, cheers I read that article literally 2 days ago after using the full text index in mssql. However this doesn't help me exactly as my problem is not with the search but it's on the reviews page as I need to be able to say reviews.php?rid=1 and then it would return which page the review is on based on the requirements mentioned above.
 
Oops sorry I missed the other post, na I really have to do it this way afraid.
 
It's going to be extremely complicated to get the page the article is located in because as more articles are added, the page it is in is going to change. You should alter your reviews page to just output the single article onto the page when an Id is provided. If there is no Id then revert to 15 articles per page.
Otherwise you'll have to do several queries to calcualte the position of the article.

Query all article id's and put the reults into an array and search for the ID that was returned by the search in the array.
Then divide the position in the array in whitch it is located by 15 and round up to get the page number (3.5 would be in the fourth page). The exact position on the page however will be impossible to pinpoint.




----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
I agree, change your path young grasshopper for the future shows nothing but a path of suffering and hardship.

While you have the chance to do it right, and make it more easy to manage, more professional and alot less work, make the change!.



______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top