Integrating articles into a slider

0

I'm working on an article slider, whose articles are in a database that can be deleted / added (CMS), everything is working perfectly, the database, and the slider. Now I just wanted to integrate the articles into the slider. Here is my code, what is happening is that the articles are all appearing at the same time on top of each other, any tips?

JS:

sliderInt=1;
sliderNext=2;
$("#newsText > p#1").fadeIn(500);
startSlider();

function startSlider() {
    count = $("#newsText > p").size();
    loop = setInterval (function() {
        if (sliderNext>count) {     
            sliderNext = 1;
            sliderInt = 1;
        }

    $("#newsText > p").fadeOut(500);
    $("#newsText > p#" + sliderNext).delay(500).fadeIn(500);
    sliderInt = sliderNext;
    sliderNext ++;

    } ,7500);
}

function stopLoop() {
    window.clearInterval(loop);
}

function showSlide(id) {
    stopLoop();
        if (id>count) {       
            id = 1;
      }
        else if (id<1) {
            id=count;
      }

    $("#newsText > p").fadeOut(500);
    $("#newsText > p#" + id).fadeIn(500);

    sliderInt = id;
    sliderNext = id + 1;
    startSlider();
}
})

PHP:

<?php
include_once('php/CMS/includes/connection.php');
include_once('php/CMS/includes/article.php');

?>
.......HTML....
<?php 

                for ($id=1; $id < count($articles); $id++) {
                    echo ("<p id=".$id.">".$articles[$id]['article_content']."</p>");
                }

            ?>
    
asked by anonymous 13.03.2014 / 11:23

1 answer

0

Your problem is in this code snippet:

foreach ($articles as $article) {
    for ($articles=0; $articles <= count($articles); $articles++) {
         $id = 1;
         echo ("<p id =".$id++.">".$article['article_content']."</p>");
    }
}

Take out the foreach that is outside the for and use only the for counter to increase id s div s. By default, you can not have elements with the same id in an HTML page.

Suggestion for correction:

$article = new Article;
$articles = $article->fetch_all();
for ($i=0, $count=sizeof($articles); $i<$count; $i++) {
     echo ("<p id='article_".$i."'>".$articles[$i]['article_content']."</p>");
}
    
13.03.2014 / 13:55