SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Zealot
    Join Date
    Jun 2006
    Posts
    111
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    php loop to split list

    Hello, when I return values from my database I am outputing them into a <li> tag but long list will make the page huge... I know I need to use a for loop to break up the <li> and put a </ul> in there somewhere but cant figure out how to do this... if someone could help, id be greatly appreciative. Hers the code....
    Code:
    <ul>
    while ($data = mysql_fetch_array($query, MYSQL_ASSOC))
    {
    	$city= $data['city'];
    	$citylower= strtolower($city);
    
    	echo "<li><a href='rate-page.php?state=$state&city=$city'>$city</a></li>";
    		
    }
    
    
    echo "</ul>";

  2. #2
    Non-Member
    Join Date
    Oct 2009
    Posts
    1,852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No, you don't need for loop.
    you need, probably, LIMIT sql operator and some paginating code, I guess

  3. #3
    SitePoint Zealot
    Join Date
    Jun 2006
    Posts
    111
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    dont think so....

  4. #4
    SitePoint Guru
    Join Date
    Jan 2005
    Location
    heaven
    Posts
    953
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by tytyguy View Post
    dont think so....
    He's kinda right.
    Creativity knows no other restraint than the
    confines of a small mind.
    - Me
    Geekly Humor
    Oh baby! Check out the design patterns on that framework!

  5. #5
    SitePoint Wizard
    Join Date
    Nov 2005
    Posts
    1,191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    probably wants say 100 cities in 5 floated lists of 20??
    you could use array_chunk() or modulo, or just a plain old counter

  6. #6
    SitePoint Zealot
    Join Date
    Jun 2006
    Posts
    111
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    can you explain more?

  7. #7
    Non-Member
    Join Date
    Oct 2009
    Posts
    1,852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    can you explain more?
    give us an example of html that you want

  8. #8
    SitePoint Zealot
    Join Date
    Jun 2006
    Posts
    111
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok... I am outputting this right now....

    <ul>
    <li>kansas</li>
    <li>nevada</li>
    <li>nebraska</li>
    <li>alaska</li>
    <li>alabama</li>
    <li>new york</li>
    </ul>

    (of course its 52 list items)

    and I want...

    <ul>
    <li>alaska</li>
    <li>alabama</li>
    <li>new york</li>
    </ul>

    <ul>
    <li>kansas</li>
    <li>nevada</li>
    <li>nebraska</li>
    </ul>


    after 5 li's I want to end the ul and start a new one, but keep running through the array so it splits 52 states from one ul into 10 uls

    edit: and I dont want paging. this is just for a single div on my homepage, so pagination would not be applicable.

  9. #9
    Non-Member
    Join Date
    Oct 2009
    Posts
    1,852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You said before that "long list will make the page huge".
    So, you think that this parted list will make the page smaller?

  10. #10
    SitePoint Zealot
    Join Date
    Jun 2006
    Posts
    111
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well I can float the uls left so I can have atleast 3-4 uls across the page. I woulndt image it would only be 2 rows by 4-5 columns.

    ..not very big. theres only 50 states.

  11. #11
    Non-Member
    Join Date
    Oct 2009
    Posts
    1,852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can make it as with pencils.
    Count to 5 and then put "</ul><ul>" out.
    Usually we count using a variable.

  12. #12
    SitePoint Zealot
    Join Date
    Jun 2006
    Posts
    111
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    wow...thanks


Bookmarks

Posting Permissions

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