Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 3 123 LastLast
Results 1 to 15 of 37
  1. #1
    Regular Coder
    Join Date
    Sep 2010
    Posts
    331
    Thanks
    9
    Thanked 6 Times in 6 Posts

    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?

    Array:
    PHP Code:
    <?php
    $id
    =array("http://www.lockerz.com/clickthrough/click/34847/2922","http://www.lockerz.com/clickthrough/click/210197/3098");
    ?>
    Iframe:
    Code:
    <iframe 
        src="<?php echo $id; ?>">"
        width="100%"
        height="100%">
    </iframe>

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,525
    Thanks
    8
    Thanked 1,091 Times in 1,082 Posts
    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



    .

  • #3
    Regular Coder
    Join Date
    Sep 2010
    Posts
    331
    Thanks
    9
    Thanked 6 Times in 6 Posts
    Quote Originally Posted by mlseim View Post
    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.

  • #4
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Quote Originally Posted by elitis View Post
    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.

  • #5
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,525
    Thanks
    8
    Thanked 1,091 Times in 1,082 Posts
    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:

    http://www.lockerz.com/clickthrough/click/34847/2922
    http://www.lockerz.com/clickthrough/click/210197/3098
    etc.


    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.



    .

  • #6
    Regular Coder
    Join Date
    Sep 2010
    Posts
    331
    Thanks
    9
    Thanked 6 Times in 6 Posts
    Quote Originally Posted by MattF View Post
    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 View Post
    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:

    http://www.lockerz.com/clickthrough/click/34847/2922
    http://www.lockerz.com/clickthrough/click/210197/3098
    etc.


    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

  • #7
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,542
    Thanks
    45
    Thanked 259 Times in 256 Posts
    Quote Originally Posted by elitis View Post
    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?

  • #8
    Regular Coder
    Join Date
    Sep 2010
    Posts
    331
    Thanks
    9
    Thanked 6 Times in 6 Posts
    Quote Originally Posted by Keleth View Post
    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.

  • #9
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Add a timestamp column to the table, update it for the entry each time that specific entry is chosen and sort by the timestamp column.

  • #10
    Regular Coder
    Join Date
    Sep 2010
    Posts
    331
    Thanks
    9
    Thanked 6 Times in 6 Posts
    Quote Originally Posted by MattF View Post
    Add a timestamp column to the table, update it for the entry each time that specific entry is chosen and sort by the timestamp column.
    wait what table? Thought "we" decided to use a plain text file for the urls

  • #11
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,542
    Thanks
    45
    Thanked 259 Times in 256 Posts
    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?

  • #12
    Regular Coder
    Join Date
    Sep 2010
    Posts
    331
    Thanks
    9
    Thanked 6 Times in 6 Posts
    Quote Originally Posted by Keleth View Post
    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?

  • #13
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,525
    Thanks
    8
    Thanked 1,091 Times in 1,082 Posts
    well technically it was working in my database
    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.


    .
    Last edited by mlseim; 11-11-2010 at 05:10 AM.

  • #14
    Regular Coder
    Join Date
    Sep 2010
    Posts
    331
    Thanks
    9
    Thanked 6 Times in 6 Posts
    Quote Originally Posted by mlseim View Post
    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.

  • #15
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Quote Originally Posted by elitis View Post
    And there really isn't a problem.
    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.


    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.


  •  
    Page 1 of 3 123 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •