0

At the moment i'm showing a slider out of my database on my website with this piece of code:

<?php
$query="SELECT * FROM seo_slider ORDER BY id";
$stmt = $pdo->query($query);
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);

foreach ($result as $row) {
?>

<ul class="rslides">
    <li><figure><a href="<?php echo $row['link']; ?>"><img src="http://www.onderdemolen.nl/images/slider/<?php echo $row['id']; ?>.jpg" alt="<?php echo $row['titel']; ?>" /></a>
    <div class="caption"><div class="titel"><h1><?php echo $row['titel']; ?></h1></div><div class="beschrijving"><h3><?php echo $row['caption']; ?></h3></div></div></figure></li>
</ul>

<?php
}
?>  

In my table seo_slider I also have a field called "actief" in here it says 0 or 1. I want that the slides on my website only to show when the slide has 0 in "actief". And when it says 1 the slide won't show on my website. I already tried some things but can't get it to work. Would be nice if somebody could help me!

Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119

2 Answers2

0

Put it within an if statement:

foreach ($result as $row) {
    if($row['actief'] == 0){
?>

<ul class="rslides">
<li><figure><a href="<?php echo $row['link']; ?>"><img src="http://www.onderdemolen.nl/images/slider/<?php echo $row['id']; ?>.jpg" alt="<?php echo $row['titel']; ?>" /></a>
<div class="caption"><div class="titel"><h1><?php echo $row['titel']; ?></h1></div><div class="beschrijving"><h3><?php echo $row['caption']; ?></h3></div></div></figure></li>
</ul>

<?php
    }
}
?>  
Reece Kenney
  • 2,734
  • 3
  • 24
  • 57
0

You can run the following query:

SELECT * FROM seo_slider WHERE actief=0 ORDER BY id

That will make the database return only registers where the column you want is equal to 0.
It's better than checking the value in PHP code.

Phiter
  • 14,570
  • 14
  • 50
  • 84
  • Well that wasn't that hard xD thanks! I was trying all kinds of stuff with if statements and equals... My PHP knowledge isn't that big yet. – Rolinda Strijker Mar 09 '16 at 13:20