I have a mysql question.
I have a news section on my website, and I want to display the two latest items. If I do:
SELECT * FROM nieuws ORDER BY id DESC LIMIT 1
it selects the latest item, and now I want to select the second to last item.
Do you guys know how to do it?
/// EDIT
Now it doesn't work, here's my code: (I have connect included ;) )
            $select = mysql_query("SELECT * FROM nieuws ORDER BY id DESC LIMIT 1");
            while($row = mysql_fetch_assoc($select)) {
            $datum = $row['time'];
            $titel = $row['title'];
            $bericht = $row['message'];
            ?>
            <div class="entry">
                <span class="blue date"><?php echo "$datum"; ?></span>
                <h3><?php echo "$titel"; ?></h3>
                <p><?php echo "$bericht"; ?></p> <br />
            </div><!-- end of entry --> <?php } ?>
            <?php 
            $select2 = mysql_query("SELECT * FROM nieuws ORDER BY id DESC LIMI 1, 1");
            while($row2 = mysql_fetch_assoc($select2)) {
                $datum = $row2['time'];
                $titel = $row2['title'];
                $bericht = $row2['message'];
                ?>
            <div class="entry">
                <span class="green date"><?php echo "$datum"; ?> </span>
                <h3><?php echo "$titel"; ?></h3>
                <p><?php echo "$bericht"; ?></p>
            </div> <!-- end of entry --> <?php } ?>
        </div><!-- end of news --> 
                SELECT * FROM nieuws ORDER BY id DESC LIMIT 2 - selects last 2 items
SELECT * FROM nieuws ORDER BY id DESC LIMIT 1, 1 - selects only second item
LIMIT can take two arguments:
SELECT ... LIMIT 1, 1
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With