January 3, 201412 yr Hello, I was wondering if someone could help me with my following problem, I want a real basic text ticker in the top of my page and it has to take all the information from the database. I found this ticker called "jquery_news_ticker" and it does a perfect job for my cause. But everytime it takes the information from the database it shows the ticker multiple times below each other. I searched on the internet and found that it was a loop problem, I should put it in a while loop and then it should function normally. But there comes my problem, I cannot get it functioning. Here is my code without while loop (showing it multiple times): <?php include_once 'handler.php'; $teams = getTeams(); ?> <?php foreach ($teams as $team) { $leden = getLeden($team["id"]); ?> <link href="jquery_news_ticker/styles/ticker-style.css" rel="stylesheet" type="text/css" /> <script src="jquery_news_ticker/includes/jquery.ticker.js" type="text/javascript"></script> <ul id="js-news" class="js-hidden"> <li class="news-item"><a href="#"><?php echo $team ["telefoon"]; ?></a></li> </ul> <script type="text/javascript"> $(function () { $('#js-news').ticker(); }); </script> <?php } ?> Hopefully someone could help me with this problem.. Thanks in advance! ps. I'm just a beginner with PHP..
January 3, 201412 yr The foreach is in the wrong place, you want to loop the <li> and not the whole thing. The following should work. <?php include_once 'handler.php'; $teams = getTeams(); ?> <link href="jquery_news_ticker/styles/ticker-style.css" rel="stylesheet" type="text/css" /> <script src="jquery_news_ticker/includes/jquery.ticker.js" type="text/javascript"></script> <ul id="js-news" class="js-hidden"> <?php foreach ($teams as $team) { $leden = getLeden($team["id"]); ?> <li class="news-item"><a href="#"><?php echo $team ["telefoon"]; ?></a></li> <?php } ?> </ul> <script type="text/javascript"> $(function () { $('#js-news').ticker(); }); </script>
Create an account or sign in to comment