Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Aug 2004
    Location
    Nashville
    Posts
    202
    Thanks
    0
    Thanked 0 Times in 0 Posts

    mysql row output in 2 colums

    Hey everyone. I've done some searching and cant come up with my answer. Also I'm not thinking straight thanks to a "summer flu" so I figured Id ask for some help.

    I've got a music reviews feature on the front page of my site. I've got my results limited to 0, 4. What I'm looking for is the results to show up:

    Row 1 | Row 2
    Row 3 | Row 4

    Here a simple row output:

    PHP Code:
    .<? 
    echo "<table>";
         
    $result mysql_query("SELECT * FROM album_review ORDER BY id DESC LIMIT 0,4");
                while(
    $myrow mysql_fetch_assoc($result)) {
                        
                echo 
    "<tr><td><img align=\"left\" src=\"../images/album_review/$myrow[assoc_img]\" width=\"100\" height=\"100\" class=\"story\" alt=\"MISSING IMAGE\">";
                echo 
    "<h3>$myrow[title]</h3><br>";
                echo 
    "$myrow[intro_text]</td></tr>";
                
                
                } echo 
    "</table>"?>
    Desired HTML output:
    Code:
    <table><tr><td></td><td></td></tr><tr><td></td><td></td></tr></table>
    Hope this is enough info to get an answer.

    Thanks in advance

  • #2
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    PHP Code:
    <?  
    echo "<table><tr>"
         
    $result mysql_query("SELECT * FROM album_review ORDER BY id DESC LIMIT 0,4"); 
                for(
    $i 0$myrow mysql_fetch_assoc($result); $i++) { 
                echo (
    $i 2) ? '</tr><tr>' '';
                echo 
    "<td><img align=\"left\" src=\"../images/album_review/$myrow[assoc_img]\" width=\"100\" height=\"100\" class=\"story\" alt=\"MISSING IMAGE\">"
                echo 
    "<h3>$myrow[title]</h3><br>"
                echo 
    "$myrow[intro_text]</td>"
                 
                 
                } echo 
    "</tr></table>"?>
    Should do the trick.
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.

  • #3
    Regular Coder
    Join Date
    Aug 2004
    Location
    Nashville
    Posts
    202
    Thanks
    0
    Thanked 0 Times in 0 Posts

    close

    That's very close but it's strange:


    Row 1 |
    Row 2 | Row 3
    Row 4 |


    ^^^ That's what it's giving me rather than:

    Row 1 | Row 2
    Row 3 | Row 4

    any suggestions

  • #4
    Regular Coder
    Join Date
    Aug 2004
    Location
    Nashville
    Posts
    202
    Thanks
    0
    Thanked 0 Times in 0 Posts

    **solved

    I just took the echo ($i % 2); row and sent it to the bottom of the loop and it made a working difference.

    PHP Code:
    <?  
            
    echo "<table><tr>"
         
    $result mysql_query("SELECT * FROM album_review ORDER BY id DESC LIMIT 0,4"); 
                for(
    $i 0$myrow mysql_fetch_assoc($result); $i++) { 
                
                echo 
    "<td><img align=\"left\" src=\"../images/album_review/$myrow[assoc_img]\" width=\"100\" height=\"100\" class=\"story\" alt=\"MISSING IMAGE\">"
                echo 
    "<b>$myrow[title]</b><br>";
                echo 
    "$myrow[intro_text]</td>"
                echo (
    $i 2) ? '</tr><tr>' '';
                 
                 
                } echo 
    "</tr></table>"?>


  •  

    Posting Permissions

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