Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i'm using pdo to insert images from a database to a bootstrap carousel by that i mean ( loading The image path ) but the problem is when i use fetchall(); or fetch i get all rows value like this :-

What I have tried:

require_once '..\Config.php';

$dbCon = "mysql:host=$host;dbname=$db_name";
$conn = new PDO($dbCon, $username, $password);
$getquery = $conn->prepare('SELECT (imageurl) FROM special');
$getquery->execute();
$result = $getquery->fetchall();
echo $result['imageurl'];

the output is : ( Efexor.jpg path upload/17.jpg upload/17.jpg upload/19.jpg upload/18.jpg upload/18.jpg ) ...

that is all rows from imageurl column so when i loop foreach ($result) to load images from database to a bootstrap carousel it dose't work


my code : -

<div id="demo" class="carousel slide" data-ride="carousel">

  <!-- Indicators -->
  <ul class="carousel-indicators">
  <?
    $i = 0;
    foreach($result as $row){
        $actives = '';
    if($i == 0){
        $actives ='active';
    }
    ?>
    <li data-target="#demo" data-slide-to="<?= $i; ?>" class="<?= $actives;?>"></li>
    <? $i++ ; }?>
  </ul>

  <!-- The slideshow -->
  <div class="carousel-inner">
  <?
    $i = 0;
    foreach($result as $row){
        $actives = '';
    if($i == 0){
        $actives ='active';
    }
    ?>
    <div class="carousel-item  <?= $actives;?>">
      <img src="<?= $row['imageurl']?>">
    </div>
    <? echo $row['imageurl'];?>
    <? $i++; }?>
  </div>

  <!-- Left and right controls -->
  <a class="carousel-control-prev" href="#demo" data-slide="prev">
    <span class="carousel-control-prev-icon"></span>
  </a>
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900