Need help with php array

Discussion in 'PHP' started by khan11, Sep 8, 2007.

  1. #1
    Hello all,

    i need some help from you guys.

    I've created an array, for example:

    $arrayName = array ("my text a","my text b","my text c");

    suppose i have 20 elements in my array..

    i used this method to display my array:

    $value = current ($arrayName );
    echo "$value<br>";
    $value = next ($arrayName );
    echo "$value<br>";

    what i want want now is that, i want to display this array values on different pages.

    Like, it display 0 to 10 array values on first page and 10 to 20 values on second page.

    I hope you guys understand what i want...


    If anyone can help quick... please reply here.


    Thank you!!
     
    khan11, Sep 8, 2007 IP
  2. Synchronium

    Synchronium Active Member

    Messages:
    463
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    58
    #2
    $start = 0; // Could be 10, 20... whatever the start number of the record set
    $finish = 10 // 20, 20 etc... The number of records you want to display
    for ( $count = $start; $count < $arrayName || $count = $finish; $count++ ) {

    echo $arrayName[$count];

    }
     
    Synchronium, Sep 8, 2007 IP
  3. khan11

    khan11 Active Member

    Messages:
    615
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    58
    #3
    well thanks for the script but im facing some problem...


    the page is keep loading but not showing the stuff...
    here is what i have added but the page is keep loading..

    please check this out..

    $firstpoint = "0"; // Could be 10, 20... whatever the start number of the record set
    $endpoint = "10"; // 20, 20 etc... The number of records you want to display
    for($count = $firstpoint; $count < $friend || $count = $endpoint; $count++)
    {
    echo $friend[$count];
    };


    thanks for quick help..
     
    khan11, Sep 8, 2007 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #4
    
    $count = $endpoint;
    
    PHP:
    There should be two equal signs.
     
    nico_swd, Sep 8, 2007 IP
  5. khan11

    khan11 Active Member

    Messages:
    615
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    58
    #5
    still same problem...


    could you please first check it in your pc to make sure if it works..
     
    khan11, Sep 8, 2007 IP
  6. streety

    streety Peon

    Messages:
    321
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #6
    
    $start = 0; //We'll just set it at 0 but you might like to get this from a GET variable
    $length = 10;
    $sliced_array = array_slice($arrayName, $start, $length);
    
    foreach ($sliced_array as $item) {
    echo $item;
    }
    
    
    PHP:
     
    streety, Sep 8, 2007 IP
    khan11 likes this.
  7. khan11

    khan11 Active Member

    Messages:
    615
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    58
    #7
    woooooooo!!!

    It worked!

    thank you so much!
    + goes to you!
     
    khan11, Sep 8, 2007 IP
  8. streety

    streety Peon

    Messages:
    321
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #8
    No worries. Rewriting it seemed simpler than figuring out why the previous attempts didn't work.
     
    streety, Sep 8, 2007 IP
  9. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #9
    Lol, I find that a little bit offensive, to be honest.

    It's amazing how you expect free help, and on top of that expect that it works flawlessly on first try.

    I'm not going to set up everything locally to test a 5 line script. So, sorry if I wasted 5 seconds of your time.
     
    nico_swd, Sep 8, 2007 IP
  10. khan11

    khan11 Active Member

    Messages:
    615
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    58
    #10
    no probs..


    Well, i need some more help if you could solve this one..

    I'm using the rating script for my website files & i manually gave the file names to the rating script..

    Please check the following script.

    the thing i highlighted in red.. i want to display it in array but it doesn't work.. when i try to echo it using variable, it works but i want it to add in all of my files on one page... so i need to put this thing here where it is highlighted..

    any solution??
     
    khan11, Sep 9, 2007 IP
  11. streety

    streety Peon

    Messages:
    321
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #11
    I'm not at all sure I know what you're trying to achieve here. If you could go into a bit more of the background and/or show us some of the code surrounding this it might help.

    On the off chance I'm not totally confused though try putting curly brackets around the function - {rating_bar('02','5')}
     
    streety, Sep 9, 2007 IP
  12. khan11

    khan11 Active Member

    Messages:
    615
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    58
    #12
    well, i think we cannot do that..

    I changed my idea now..

    What i was trying to do: i wanted to display tables and their elements using array & also i wanted to load a variable inside an array...


    Now im simply using it with dreamweaver & linking to php for array work..

    Thank you..
     
    khan11, Sep 9, 2007 IP