0

I have a table with fields like id, date, heading, news. I want to display the fields date, heading and news in an Owl Carousel slider. Can anyone suggest how to pick two rows at a time from an SQL table to display two entries at a time in the Owl Carousel slider. I have used an SQL query like this:

<?php
$sql3 = "SELECT date, heading, news FROM news ORDER BY news.date LIMIT 0, 1";
$result3 = mysql_query($sql3) or die(mysql_error());
while($row3 = mysql_fetch_array($result3)) {
    ?>
    <div class="item ">
        <div class="l_blk">
            <div class="news_container">
                <div class="col-md-1 date_b"><p>Mar<br>09</p></div>
                <div class="col-md-11 cont_b">
                    <p>
                        <span class="news_t">"<?php echo $row3['heading']; ?>"</span><br>
                        <?php echo $row3['news']; ?>
                    </p>
                </div>
            </div>
        </div>
        <div class="l_blk">
            <div class="news_container">
                <div class="col-md-1 date_b"><p>Mar<br>09</p></div>
                <div class="col-md-11 cont_b">
                    <p>
                        <span class="news_t">"<?php echo $row3['heading']; ?>"</span><br>
                        <?php echo $row3['news']; ?>
                    </p>
                </div>
            </div>
        </div>
    </div>
    <?php
}
?>

Can anyone suggest how to do this?

Antti29
  • 2,953
  • 12
  • 34
  • 36
Anna
  • 53
  • 5

2 Answers2

0
$sql3 = "SELECT date, heading, news FROM news  ORDER BY news.date LIMIT 0, 1";

Don't you change the LIMIT 0, 2

Which means select 2 starting with the value at index 0?

Once you've done that, take out the duplicate code inside the loop

Brett
  • 1,951
  • 2
  • 28
  • 35
  • no..its not working..when 2 is given,it only selects 2 rows from the table and displays them only.it doesnot select the rest of the rows in the table.. – Anna Apr 28 '16 at 06:12
  • @Anna but you are only selecting 1 row in the sql. You need to select multiple rows and change the owl carousel slider (or the css) to make it display 2 at a time. This isn't a php/html issue – Brett Apr 28 '16 at 06:15
0

Try this pls.

<?php

$sql3 = "SELECT date, heading, news FROM news  ORDER BY news.date"; // No limit
$result3= mysql_query($sql3) or die(mysql_error());

$counter = 0;
while($row3 = mysql_fetch_array($result3, MYSQL_ASSOC))
{
    if($counter % 2 == 0){
        echo '<div class="item ">'.PHP_EOL;
    }
    ?>
        <div class="l_blk">

            <div class="news_container">

                <div class="col-md-1 date_b"><?php $row3['date'] ?></div>

                <div class="col-md-11 cont_b">

                    <p>

                        <span class="news_t">"<?php echo $row3['heading']; ?>"</span><br>

                        <?php echo $row3['news']; ?>

                    </p>

                </div>

            </div>

        </div>
<?php
    if($counter % 2 == 1){
    echo '</div>'.PHP_EOL;
    }
    $counter++;
}
if($counter % 2 == 1){
    echo '</div>'.PHP_EOL;
}
?>
Metin
  • 21
  • 4