Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End [Solved] Loops and making new divs after so many records.

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #27731
    davebandit
    Member

    Thanks in advance for any help.

    I am working on a site that uses a flat file to store some records. I am using a jQuery slider to display information on each record in the flat file. I need a new div to be created after four records are displayed so the slider has a new page.

    How do I loop through the records and create a new div after four records are pulled?

    Right now I just have a for loop that displays all the records in one long line.

    Code:
    $albumList = file(“../albums/albumtlist.txt”);

    foreach($albumList as $Key => $Val)
    {
    //explode that data into a new array:
    $album[$Key] = explode(“||”, $Val);
    }

    Then Later it displays the records and puts them into Divs for a slider. I want to put four records into each div but here is how my code looks to display them all out in one long line.

    Code:

    jinfiesto
    Member

    Hmmm. I would go ahead and write a function to do what you want. Instead of looping, I would write it recursively. What you could do is initialize $K, and then set up a conditional statement to evaluate the value of $K at every pass through the function and based on the value of $K put stuff into divs. So maybe something like.

    *Pseudo-code*

    Code:
    function divsilliness
    $K++
    If $K<4

    Your stuff here

    else
    end

    And then you’d have to do something like this

    Code:
    function checkrecords
    if *records has stuff in it*
    *call function divsilliness*
    *call self again*
    else
    end

    Sorry, I’m too lazy to actually write it out, but I think it should go something like that.

    #70340
    davebandit
    Member

    Thank you for the response.

    I was thinking along the sames lines, I was just hoping there was a more elegant way to do what I was thinking.

    My problem with using a function with the "if $K<4…blah blah…" was the loop used $K ;ater down the line while the whole thing was looping for each record, and with 50 plus records it needed to be incremental.

    So I ending up something like this (I decided to go with groups of 8 instead of 4)

    Code:
    ‘;
    } // Rest of loop below

I was using the EasySLider jQuery Plugin http://cssglobe.com/post/4004/easy-slider-15-the-easiest-jquery-plugin-for-sliding so a new line item created a new slider panel. Same idea if it were divs, just echo a closing and opening tag…

I will just have to manually increase the multiple of 8 values if the records grow above 72 entries (this may take awhile.)

So a simple solution for my question. Not Completely elegant or clever as using functions but simple enough.

Viewing 3 posts - 1 through 3 (of 3 total)