Reputation: 503
I am currently trying to set up some sort of pagination in PHP but not having much luck. All of the tutorials I find are sequential ones done by ID so +1 or -1 but in my situation that will not work.
I am trying to display different delivery addresses linked to customers. So far I have connected to MySQL, ran the query to get what information I need and put it into an array, This array now stores an ID and a customer ID. Each ID is different because they have been added at different times. For example one is 379 in the same Customer ID is also 707, so I cannot just +1.
I hope these details can help.. Is there any way of setting it up so the links generated will only have those IDs ? So if a user chooses say, Customer ID 14, then they can see only the delivery addresses linked to 14, which might be delivery address 300 and 500?
Thank you so much for reading if you get this far, I have no idea and I have nearly pulled all of my hair out!
Upvotes: 1
Views: 197
Reputation:
OK, so you're getting the IDs of your customer addresses and putting that number as the index value in your array.
You wish to interate through your array but you can't iterate + 1 because of the numbers.
Use foreach()
on the array. E.g.
foreach ($array as $key=>$value) {
echo "$key : $value <br />";
}
$key
will be the ID of the address that you set. You can manipulate this to create links only to those addresses. I hope I've understood what you're asking for.
Upvotes: 1