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 3 of 3
  1. #1
    New Coder
    Join Date
    Jan 2011
    Posts
    14
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Add a new box for every news article

    On my site, I am trying to make the code below add a new box for each news article in the database.
    So far i have only managed to get it to output the first article in a box before it puts all the articles inside the first articles's box rather than a box of their own. (If that was a bit hard to understand, i have put 2 images to show how i need it to work)

    Currently it does this:


    I need it to do this


    the code i have so far is.
    PHP Code:
    <?php
                    $query 
    mysql_query('SELECT * FROM news ORDER BY id DESC LIMIT 1');
                    while(
    $output mysql_fetch_assoc($query))
                    {
                    
    ?>
                    <div class="bs-docs-example">
                      <div class="accordion" id="accordion2">
                        <div class="accordion-group">
                          <div class="accordion-heading">
                            <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#<?php echo $output['id']; ?>">
                            <?php
                            
    echo $output['subject'].'<br />';
                            
    ?>
                            </a>
                          </div>
                          <div id="<?php echo $output['id']; ?>" class="accordion-body collapse">
                               <?php 
                               
    echo '<div class="accordion-inner">';
                               echo 
    $output['news'].'<br / >'?>
                               <br>
                              <br><blockquote class="pull-right"><?php
                              
    echo 'Posted by '.$output['postedby']; 
                              
    ?>
                              </blockquote>
                              <?php ?>
                            </div>
                          </div>
                        </div>
                      </div>
                    </div>

  • #2
    New Coder
    Join Date
    Jan 2011
    Posts
    14
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Anyone able to help?

  • #3
    Regular Coder Custard7A's Avatar
    Join Date
    Jul 2010
    Location
    Australia
    Posts
    286
    Thanks
    32
    Thanked 33 Times in 33 Posts
    Uh, because you are closing your while loop before all the divs are ended?

  • Users who have thanked Custard7A for this post:

    jake_grant (12-24-2012)


  •  

    Posting Permissions

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