Een PHP loop in een script

Overzicht Reageren

Sponsored by: Vacatures door Monsterboard

Marc DEVLIEGER

Marc DEVLIEGER

14/09/2023 16:08:58
Quote Anchor link
Hallo,

Via MySQL DB waar nieuwsberichten in bewaard worden wil ik deze laten verschijnen op het scherm als deze geactiveerd worden. Dit lukt mij en krijg het eerste bericht te lezen. Nu wil ik meerdere berichten activeren in het volgende script...

1. PHP script oproep nieuwsberichten

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<?php

$sql
= "SELECT * FROM BreakingNews WHERE Activatie = '1'";
$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0) {
  // output data of each row
  while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
 
    //$ResultQuotes = "... " . $row["Titel"].  " ...<br>";
    //printf ("%s (%s)\n", $row["Titel"], $row["Nieuws"]);

    printf ("%s %s ", $row["Titel"], $row["Nieuws"]);
    
    $ResultBreakingNews_Titel = $row["Titel"];
    $ResultBreakingNews_Nieuws = $row["Nieuws"];
    
    
  }
}
else {
  echo "0 results";
}


mysqli_free_result($result);

?>


2. HTML script zichtbaar maken nieuwsberichten

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<html>
<body>


<div class="row py-2">
  <div class="col-2 col-sm-1 col-md-3 col-lg-2 py-1 pe-md-0 mb-md-1">
    <div class="d-inline-block d-md-block bg-primary text-white text-center breaking-caret py-1 px-2">
      <svg xmlns="http://www.w3.org/2000/svg" width="1rem" height="1rem" fill="currentColor" class="bi bi-lightning-fill" viewBox="0 0 16 16">
        <path d="M11.251.068a.5.5 0 0 1 .227.58L9.677 6.5H13a.5.5 0 0 1 .364.843l-8 8.5a.5.5 0 0 1-.842-.49L6.323 9.5H3a.5.5 0 0 1-.364-.843l8-8.5a.5.5 0 0 1 .615-.09z"/>
      </svg>
      <span class="d-none d-md-inline-block">Breaking news</span>
    </div>
  </div>

  <!--Breaking content-->
  <div class="col-10 col-sm-11 col-md-9 col-lg-10 ps-1 ps-md-2">
    <div class="breaking-box pt-2 pb-1">
      <!--marque-->
      <marquee behavior="scroll" direction="left" onmouseover="this.stop();" onmouseleave="this.start();">
  
        <span class="position-relative mx-2 badge bg-primary rounded-0"><?php echo $ResultBreakingNews_Titel ?></span><?php echo $ResultBreakingNews_Nieuws ?>
        <span class="position-relative mx-2 badge bg-primary rounded-0">Title 2</span> News 2
        <span class="position-relative mx-2 badge bg-primary rounded-0">Title 3</span> News 3
        <span class="position-relative mx-2 badge bg-primary rounded-0">Title 4</span> News 4
        <span class="position-relative mx-2 badge bg-primary rounded-0">Title 5</span> News 5
          
        
      </marquee>
    </div>
  </div>
</div>


</body>
</html>


Hoe kan ik dit allemaal verwerken in een LOOP beweging :

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
<html>
<body>

<span class="position-relative mx-2 badge bg-primary rounded-0"><?php echo $ResultBreakingNews_Titel ?></span><?php echo $ResultBreakingNews_Nieuws ?>


</body>
</html>
Gewijzigd op 14/09/2023 16:23:14 door Marc DEVLIEGER
 
PHP hulp

PHP hulp

28/04/2024 15:58:18
 
- Ariën  -
Beheerder

- Ariën -

14/09/2023 16:11:06
Quote Anchor link
Kun je jouw script tussen code tags plaatsen? Dan is het beter leesbaar.
 



Overzicht Reageren

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.