Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Database displays multiple times

Featured Replies

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..

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

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.