SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: Loop Problem

  1. #1
    SitePoint Addict
    Join Date
    Feb 2006
    Posts
    247
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Loop Problem

    Hey guys, I have a list of users that I'm trying to pull from a database. Now, I can list them in a horzintal fashion, but I'd like to have more control over how the names are layed out.

    Currently, they are simplying layed out as such

    user1 user2 user3 user4 user5 user6 etc.....

    I'd like to have them layed out in rows of 5 such as this

    user1 user2 user3 user4 user5
    user6

    Here's my code.

    Code:
    while($userrslt = mysql_fetch_array($usersend)){
    			
    		for ( $counter = 1; $counter <= 1; $counter += 1) {
        	extract($userrslt);
    		echo $username;
    		echo "&nbsp;";
    		}
    	
    	}

  2. #2
    SitePoint Enthusiast
    Join Date
    Apr 2006
    Location
    UK
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That code wouldn't work, but I think you already know that
    I think the way to do this is like this:
    PHP Code:
    $i=0;
    echo 
    "<tr>";
    while(
    $userrslt mysql_fetch_array($usersend)){
    extract($userrslt);
    echo 
    "<td>".$userinfo."</td>";
    $j=$i%5;
    if (
    $j==0) {
    echo 
    "</tr><tr>";
    }

    Last edited by cdwhalley.com; Apr 20, 2006 at 14:56. Reason: Missing semicolon in php code.

  3. #3
    SitePoint Addict
    Join Date
    Feb 2006
    Posts
    247
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    that code puts each name on it's own row

  4. #4
    SitePoint Enthusiast
    Join Date
    Apr 2006
    Location
    UK
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My mistake:
    PHP Code:
    $i=0;
    echo 
    "<tr>";
    while(
    $userrslt mysql_fetch_array($usersend)){
    extract($userrslt);
    echo 
    "<td>".$userinfo."</td>";
    $j=$i%5;
    if (
    $j==0) {
    echo 
    "</tr><tr>";
    }
    $i++;//EDITED LINE

    Forgot to increment $i - sorry.


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
  •