Skip to content
Advertisement

get two paths of images from database and loop them to display in slider

Im little bit stuck on a logic.scenario is i have a slider where two images are shown at a time taking 50%-50% part of screen,here is the simple html of it,

 <div class="zeus-slider zeus-default" >
    <div class="zeus-block">
      <div class="zeus-slide s-50"> <img src="slider/slider1.jpg" data-effect="slideRight" alt=""  /> </div>
      <div class="zeus-slide s-50"> <img src="slider/slider2.jpg" data-effect="slideRight" alt="" /> </div>
    </div>
  </div>

here every block contains two images i have shown only one.now i have trying to make it dynamic, but i didnt get any idea how it will work, so i created database with two tables, each for individual image in a single block.Both table have fields like simg_id(A_I),img_name,simg_path. here its my php on slider page.

<div class="zeus-block">
       <?php 
             $slider_slt=getResultSet('select * from slider_img_master1 ORDER BY simg_id');
                    if(mysql_num_rows($slider_slt))
                        {
                            while($slider_data=mysql_fetch_assoc($slider_slt)) 
                             {
                                    ?>

      <div class="zeus-slide s-50"> <img src="slider/first/<?php echo $slider_data['simg_path']?>" data-effect="slideRight" alt=""  /> </div>

       <?php }
                } ?>




       <?php 
                    $slider_slt2=getResultSet('select * from slider_img_master2 ORDER BY simg_id');
                            if(mysql_num_rows($slider_slt2))
                                {
                                    while($slider_data2=mysql_fetch_assoc($slider_slt2)) 
                                        {
                                        ?>


      <div class="zeus-slide s-50"> <img src="slider/second/<?php echo $slider_data2['simg_path']?>" data-effect="slideRight" alt="" /> </div>

      <?php }
                } ?>
    </div>

now the problem is when i try to fetch path of image in slider, images are not changing one by one on both half of screen.instead it showing like both images from from both table top, another two images from both tables below 1st both, and so on , so full page is covered with images.

I know this idea of creating two tables for getting two images at once is silly,but i could not think any better.if any one can suggest any better way, it would be so helpful.

Update:getResultSet is function for mysql_query.

Advertisement

Answer

if anybody interested i found an answer for above question.

<div id="slide1" >
    <div class="zeus-slider zeus-default" >

    <?php
    $slider_str="select *from slider_img_master1 where simg_status='Active'";           
    $i=1;
    $result=mysql_query($slider_str);


    if(mysql_num_rows($result)>0)
    {
                echo '<div class="zeus-block">';

        while($row=mysql_fetch_assoc($result)) 
        {  
            if($i%2==1 && $i!=1)
            {
                echo '<div class="zeus-block">';

            }

        ?>
      <div class="zeus-slide s-50"> <img src="slider/<?php echo $row['simg_path'];?>" data-effect="slideRight" alt=""  />                       </div>
    <?php 
            if($i%2==0)
            {
                echo '</div>';

            }
            $i++;
        }
    } ?>
    </div>

    <div class="clear"> </div>
    <div class="next-block"> </div>
    <div class="prev-block"> </div>
  </div>
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement