While Loops

Discussion in 'PHP' started by MajHate, Mar 13, 2009.

  1. #1
    Hello,

    I am using a while loop to retrieve names from my database. After each name I have a line break (<br>) so it forms a list. However, I do not want it in one column, I would like to break it up into 3 columns. Does anyone know how to do this?

    Thank You,
    Jason
     
    MajHate, Mar 13, 2009 IP
  2. ActiveFrost

    ActiveFrost Notable Member

    Messages:
    2,072
    Likes Received:
    63
    Best Answers:
    3
    Trophy Points:
    245
    #2
    
    <?php
    $something = mysql_query("SELECT * FROM somewhere");
    $column_count = 3;
    $i = 1;
    while ($row = mysql_fetch_array($something)) {
    	
    		if (is_int($i/$column_count)) {
    			echo $row['your_value'], "<br>";
    		} else {
    			echo $row['your_value'], " - "; // remove - symbol if you don't want to split columns
    		}
    
                    $i++;
    	
    }
    ?>
    
    PHP:
     
    ActiveFrost, Mar 13, 2009 IP
  3. MajHate

    MajHate Member

    Messages:
    48
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #3
    The script you gave me displays each name 6 times. Also, is there a way to integrate an html table into that?

    Thank You
     
    MajHate, Mar 13, 2009 IP
  4. ActiveFrost

    ActiveFrost Notable Member

    Messages:
    2,072
    Likes Received:
    63
    Best Answers:
    3
    Trophy Points:
    245
    #4
    Sorry, edited - should work now ( in the same way you can implement table tags ).
     
    ActiveFrost, Mar 13, 2009 IP
  5. MajHate

    MajHate Member

    Messages:
    48
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #5
    Wait, so where's the edited script?
     
    MajHate, Mar 13, 2009 IP
  6. ActiveFrost

    ActiveFrost Notable Member

    Messages:
    2,072
    Likes Received:
    63
    Best Answers:
    3
    Trophy Points:
    245
    #6
    Do you know what means "edited" ? :confused:
     
    ActiveFrost, Mar 13, 2009 IP
  7. ads2help

    ads2help Peon

    Messages:
    2,142
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    0
    #7
    Lol. Did u saw : Last edited by ActiveFrost : Today at 12:11 am.
     
    ads2help, Mar 14, 2009 IP
  8. MajHate

    MajHate Member

    Messages:
    48
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #8
    I'm sorry, I must have a low IQ, I am so confused
     
    MajHate, Mar 14, 2009 IP
  9. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #9
    He EDITED the original script - did you test the script posted in the second post again? AFTER he edited it?
     
    PoPSiCLe, Mar 14, 2009 IP
  10. MajHate

    MajHate Member

    Messages:
    48
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #10
    I don't see a second post with the edited script. I just see the first one. Do I not know how to use a forum?
     
    MajHate, Mar 14, 2009 IP
  11. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #11
    It was edited, so the changes are reflected in the one and only post, by ActiveFrost, which says at the bottom "Last edited by ActiveFrost : Yesterday at 12:11 am." (though the specific time will be different if you are not in my time zone (Beijing/Singapore).

    If you open a document, edit it, and then hit "save", there is not suddenly a second document on your hard drive. There is just the first document, with the changes in it. Same deal here.
     
    SmallPotatoes, Mar 14, 2009 IP
  12. MajHate

    MajHate Member

    Messages:
    48
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #12
    oooooooh! I am an idiot. I apologize. I was assuming you would have posted it in a second post. I do have one more quesion, how would I integrate an html table in that code? So that each name has its own <td> and there would be a new <tr> after 3 names.

    Thank You!
     
    MajHate, Mar 14, 2009 IP