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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Row in Array

Status
Not open for further replies.

LotusE

Programmer
Nov 22, 2002
25
BE
Hello everyone,

I've got the following problem:

I want to know the number of the row that a certain value has in an array, because I want to calculate in advance on which page my item has to appear.

I know how many items I can display on one webpage and I know the total number of items I have to display. Ergo, I already know how many pages I will have. For example: 75 items, 25 items per page = 3 pages. BUT, now I want to know on what page ONE particular item will appear.

I want to do this by searching for this item in the array and retrieving the number row on which the item appears in the array. The row number is like the number of the item on my webpage, so if the row number in the array is for example 27, I know that my item will appear on page 2 (25 items per page)

Now the question is: how do I best do this, keeping in mind that the performance of the page may not suffer too much, because it is the index page of the website. Or if anyone has another suggestion/another way of dealing with this, please let me know!

Thanks in advance!

Cheers

LotusE
 
You the same mathimatical way to echo the page.
For example if you have links like that

<a href="index.php?id=39&page=2">Item</a>

I believe that you are looping througn the array to display all the items right?
in the page make this =>

<a href="index.php?id=39&page=<?=(int)(($i/25)+1)?>">Item</a>

this will give you every 25 plus one the page!

Hope this helps you!
 
Again if you do not loop! You can easily use the number of the item in the place of $i. So again if the number of the item is 23 it will give you back 1. if more than 25 it will give you the correct page!

Hope this will do the trick!
 
On my page, I show the 5 most popular adds and when the user clicks on the add, he should get to a page with all the adds from this categorie + the one that is most popular. But for some categories there are alot of pages and ergo, I need to know the number of the page the add is placed on.

I just query the 5 most popular adds and yes I query also the category into an array because I have to calculate how many adds there are and it's from this array that I need to know what the position of the most popular add is within its category.

Cheers

LotusE
 
again I believe that using this <?=(int)(($i/25)+1)?>
and in the place of $i use the number you have in the array will do the trick.

For more help please provide the array structure and how you display the link :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top