Is it possible to select an array in ascending order?
So heres the deal. I have an array with links in it. I want an iframe I have to choose the array values (not the keys) in ascending order. But I only need one, I need the iframe to get the next array value every time I refresh the page. Is this possible? Or is there something else I need to do this?
So for each user, if they refresh their page, they should see the next one?
Does that mean it remembers that when they return back a day later?
Either you'll need to use a cookie to remember their spot, or a PHP SESSION
to remember it, only for that particular visit. Not sure what you are intending to do.
The other part will involve another PHP script.
That script is what will be "sourced" into the <iframe>. And that script will read the
array, and determine which to show based on the cookie or SESSION variable.
When you say "array sort in ascending order", what does that mean?
What part of this is considered to be "ascending"?
.lockerz.com/clickthrough/click/34847/2922
So for each user, if they refresh their page, they should see the next one?
Does that mean it remembers that when they return back a day later?
Either you'll need to use a cookie to remember their spot, or a PHP SESSION
to remember it, only for that particular visit. Not sure what you are intending to do.
The other part will involve another PHP script.
That script is what will be "sourced" into the <iframe>. And that script will read the
array, and determine which to show based on the cookie or SESSION variable.
When you say "array sort in ascending order", what does that mean?
What part of this is considered to be "ascending"?
.lockerz.com/clickthrough/click/34847/2922
.
No. All I want is it to go to the next link in the array every time the page is refreshed. When I said "array sort in ascending order" that is what I meant by it. For it to go to the next link in the array every time the page is refreshed. No saving where they where,etc.
When I said "array sort in ascending order" that is what I meant by it. For it to go to the next link in the array every time the page is refreshed. No saving where they where,etc.
Regardless of what you thought you meant, that is not sorting in ascending order. You are traversing the array, not sorting it. If you don't save where they were, (which was the last key selected), you can't do it. Each page load has no idea what the last did unless you pass the relevant info to the script each time. That means using the DB, GET, sessions or cookies.
You can add to / edit or delete from that text file and the program will
use that file as the "database" for providing the sequential links. You use
Notepad to edit the file or use an online PHP edit script ... not sure what you want.
Regardless of what you thought you meant, that is not sorting in ascending order. You are traversing the array, not sorting it. If you don't save where they were, (which was the last key selected), you can't do it. Each page load has no idea what the last did unless you pass the relevant info to the script each time. That means using the DB, GET, sessions or cookies.
that is why I asked if there was something else I'd need to do.
Quote:
Originally Posted by mlseim
Would you like to create a plain text file with a list of your URL's?
So you would have a file called "url.txt" and it would look like this:
You can add to / edit or delete from that text file and the program will
use that file as the "database" for providing the sequential links. You use
Notepad to edit the file or use an online PHP edit script ... not sure what you want.
Let us know if you would like to do it that way.
.
Yeah alright. I was basically trying to use the array as my "database" since I couldn't get it to work with my real database
This is a curious point. Why was it not working in your DB?
And a general question: you want the next url based on each users refresh? Or on any refresh? ie, users cycle or the site cycles?
well technically it was working in my database. but not as I wanted to work. In my other thread (if you remember) I had the links chosen randomly. Once I tried to get the links for this to be chosen from the database in ascending order I assumed every time I refreshed the page (or when anyone refreshed the page) it would go on to the next link like with rand().
But after trying to figure out why it stayed on the same one every time, I figured out that it wouldn't go to the next one because every time I refreshed it would start at the beginning because I limited it to one link. So it did work, but I assumed it would go on to the next link like with rand().
And I want the next url every time the page is refreshed. By javascript refresh, browser refresh, etc.
mlesim suggested a file over an array... donno how any decision being made is anyone but yours. If you are going to use a file but have access to a DB, the DB is most likely the better choice, and Matt merely suggested the method by which you could implement what you tried first with the result you want?
mlesim suggested a file over an array... donno how any decision being made is anyone but yours. If you are going to use a file but have access to a DB, the DB is most likely the better choice, and Matt merely suggested the method by which you could implement what you tried first with the result you want?
thats why I put quotation marks around 'we'. But if the database is the better choice I guess I'll use that. But I'm a little confused by what matt said. Insert a timestamp column, I get what he means by that. But what does he mean by update it each time the entry is chosen?
So do you have, or do you not have, an existing database?
And is that database MySQL?
==============
The timestamp idea is good for "everyone", but not "individually".
If each user is supposed to have the experience of sequencing,
it has to be a PHP SESSION keeping track of the user's sequence
location in the database.
Let's resolve the "mystery database" problem first.
So do you have, or do you not have, an existing database?
And is that database MySQL?
==============
The timestamp idea is good for "everyone", but not "individually".
If each user is supposed to have the experience of sequencing,
it has to be a PHP SESSION keeping track of the user's sequence
location in the database.
Let's resolve the "mystery database" problem first.
.
I have an existing mysql database. And there really isn't a problem. I assumed that asc would work the same as rand(). Changing every time I refreshed.
There is for the rest of us, namely trying to find out what you actually have and specifically want. You know what you're referring to, we don't, unless you explain precisely and in exact detail.
Quote:
I assumed that asc would work the same as rand(). Changing every time I refreshed.
It doesn't. It will return results in the same ascending order each time, unless the sort criteria changes. What criteria it sorts on in ascending order is the key, hence using a timestamp column and updating it for each view. Write the code and post it if you encounter problems.