PHP & MySQL: fetch images from database -


i have uploaded multiple images , path of images have been stored together.

using explode have separated them , wish echo them in carousel

code using is:

<?php     $con=mysqli_connect("localhost","root","","db");     // check connection     if (mysqli_connect_errno())     {         echo "failed connect mysql: " . mysqli_connect_error();     }     $idd = $_get['id'];     echo "<header id='mycarousel' class='carousel slide'>";         /* indicators */         echo"<ol class='carousel-indicators'>";             echo"<li data-target='#mycarousel' data-slide-to='0' ></li>";             echo"<li data-target='#mycarousel' data-slide-to='1'></li>";             echo"<li data-target='#mycarousel' data-slide-to='2'></li>";         echo"</ol>";          $sql = "select * register_office id='".$idd."'";             $result = mysqli_query($con, $sql);             if (mysqli_num_rows($result) > 0)                  {                     /* wrapper slides*/                     echo"<div class='carousel-inner'>";                         echo"<div class='item'>";                             while($row = mysqli_fetch_assoc($result))                                  {                                     $str= $row["offimage"];                                     $array =  explode('*', $str);                                     foreach ($array $item)                                          {                                             echo "<div class='fill'>";                                             echo "<img src=\"http://example.com/abc/" . $item . "\" height=\"500\" width=\"2000\"/>";                                              echo "</div>";                                 }                            echo"</div>";                     echo"</div>";                 }                     /*controls*/                     echo"<a class='left carousel-control' href='#mycarousel' data-slide='prev'>";                         echo"<span class='icon-prev'></span>";                     echo"</a>";                     echo"<a class='right carousel-control' href='#mycarousel' data-slide='next'>";                         echo"<span class='icon-next'></span>";                     echo"</a>";                 echo"</header>";     ?> 

but showing 1 image. when use next control, after shows no image if try move forward or back.

there few problems here...

1. explode()

first, explode() may not work if $row1["offimage"] string doesn't have asterisks * between file names. in reply comment op you've given example of contents of $row1["offimage"], not separate each png file asterisk *:

@lolka_bolka outout, uploads/c376437e2a45598b2f4d89eae4f191e8.pnguploads/c376437e2a45598b2f4d89eae4f‌​191e8.png8069756be5095978123ae51fadbffe3b.pnguploads/c376437e2a45598b2f4d89eae4f‌​191e8.png8069756be5095978123ae51fadbffe3b.png04aaa414c21dc057bc594b896124068e.png  –  user3732711 dec 16 '14 @ 12:24  

for script work you've written it, expect see, example, $row1["offimage"] string looking this, asterisk * separating each png file name (with it's directory path):

 uploads/c376437e2a45598b2f4d89eae4f191e8.png*uploads/c376437e2a45598b2f4d89eae4f‌​191e8.png*8069756be5095978123ae51fadbffe3b.png 

2. div class 'item'

as "dan soap" & "rohit developer" have answered here, carousel work, need make sure each image wrapped in own item class.

your code above has echo"<div class='item'>"; before while loop.

echo"<div class='item'>"; should inside while loop - more should inside foreach loop - each image in carousel wrapped item class.

and don't forget, item or image wish have shown first (on load) should have active class too, item class, such: <div class="item active">.

3. javascript

you haven't included javascript at... without calling carousel() function, nothing happen, 1 (static) image show. may need this:

<script> $('.carousel').carousel({     interval: 3000 }) </script> 

hopefully 1 / / of these can carousel , running! :)


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -