<?php
    $sql = $pdo->query("SELECT * FROM zon_games WHERE game_slug = '".$segment['2']."'");
    $game = $sql->fetch(PDO::FETCH_ASSOC);
    if($sql->rowCount() == 0)
    {
        header('location:'.BASE_URL);
        exit;
    }
?>
<?php
    $src = $game['game_url'];
    $game_title = $game['game_name'];
    $game_category = $game['game_category'];
    $game_description = $game['game_description'];
    //$game_instruction = $game['game_instruction'];
?>
<main>
    
      <section class="game-player">
  <div class="game-frame">
   <center>
        <iframe style="width:100%;height:655px" src="<?php echo $src; ?>"
                scrolling="no" frameborder="0"></iframe>
       </center>
  </div>
</section>

    <section class="featured">
      <h2>Newest Games</h2>
      <div class="game-list">
          
          <?php $sql  = $pdo->query("SELECT * FROM zon_games ORDER BY id DESC LIMIT 8")or die(print_r($pdo->errorInfo(), true)); ?>
                    <?php while($data = $sql->fetch(PDO::FETCH_ASSOC)){ ?>
          
        <div class="game-card" onclick="location.href='<?php echo BASE_URL; ?>/games/<?php echo $data['game_slug']; ?>';" role="button">
            <?php $image_path = (empty($data['game_image_url'])) ? "" . BASE_URL . "/img/default-bg.png" : "".$data['game_image_url']; ?>
          <img src="<?php echo $image_path; ?>" alt="" />
          <h3><?php echo $data['game_name']; ?></h3>
        </div>
        
        <?php } ?>
        
      </div>
    </section>
    
    <section class="game-list-horizontal">
  <h2>Recommended Games</h2>
  <div class="game-row">
      
      <?php $sql  = $pdo->query("SELECT * FROM zon_games ORDER BY view DESC LIMIT 8")or die(print_r($pdo->errorInfo(), true)); ?>
                    <?php while($data = $sql->fetch(PDO::FETCH_ASSOC)){ ?>
                    
      
    <div class="game-card-horizontal">
        <?php $image_path = (empty($data['game_image_url'])) ? "" . BASE_URL . "/img/default-bg.png" : "".$data['game_image_url']; ?>
      <img src="<?php echo $image_path; ?>" alt="" />
      <div class="game-info">
        <h3><?php echo $data['game_name']; ?></h3>
        <p><?php echo limit_word($data['game_description'],10); ?> ...</p>
        <a href="<?php echo BASE_URL; ?>/games/<?php echo $data['game_slug']; ?>" class="play-button">Play Now</a>
      </div>
    </div>

    <?php } ?>
    
  </div>
</section>

    
  </main>