S
S
Sergey Zolotarev2019-01-17 16:50:34
MySQL
Sergey Zolotarev, 2019-01-17 16:50:34

How to make proper functional slideshow using data from MySQL?

Hello!
Now I'm facing this problem:
5c407a1fdb265043694170.png
I'm talking about the main page of my site and there is a functional slideshow container with switches and an indicator.
This slideshow has 3 sliders. Each slider contains 3 news items.


The first and second sliders work well, but when you look at the third one, this mess arises...

The site is currently being finalized and it is based on Yii1 and here are the controller and view codes for the main page:
Site Controller
<?php

class SiteController extends CController{	
     public function actionIndex(){		
         $this->pageTitle="Добро пожаловать!";	
  
         $foundname='ДОБРЫЕ-ВЗРОСЛЫЕ';
         $description='Добро пожаловать на официальный сайт Фонда помощи детям-инвалидам и инвалидам детства с ментальными расстройствами "ДОБРЫЕ-ВЗРОСЛЫЕ"!';
         $keywords='';
         Yii::app()->getClientScript()->registerMetaTag($foundname,'og:site_name',null,array());
         Yii::app()->getClientScript()->registerMetaTag("Добро пожаловать!",'og:title',null,array());
         $og_image='http://добрые-взрослые.рф/media/images/site/desktop/homepage/promo.png';
         Yii::app()->getClientScript()->registerMetaTag($og_image,'og:image',null,array());
         Yii::app()->getClientScript()->registerMetaTag($description,'Description');
         Yii::app()->getClientScript()->registerMetaTag($keywords,'Keywords');
         Yii::app()->getClientScript()->registerMetaTag($description,'og:description',null,array());
         
         Yii::app()->getClientScript()->registerMetaTag('Фонд помощи детям-инвалидам и инвалидам детства с ментальными расстройствами "ДОБРЫЕ-ВЗРОСЛЫЕ"','og:title',null,array());
      //Для первого слайдера.
         $newslist=Yii::app()->db->CreateCommand();
         $newslist->select("image,title,date,content,id");
         $newslist->from("news");
         $newslist->order("date DESC");
         $newslist->limit(3);
     
   //Для второго...
   $newslistf=Yii::app()->db->CreateCommand();
         $newslistf->select("image,title,date,content,id");
         $newslistf->from("news");
         $newslistf->order("date DESC");
         $newslistf->limit(3,3);
 
  //Для третьего.
     
   $newslistt=Yii::app()->db->CreateCommand();
         $newslistt->select("image,title,date,content,id");
         $newslistt->from("news");
         $newslistt->order("date DESC");
         $newslistt->limit(6,3);//Проблемное рассчитывание базы.
     
         $this->render('index',array("newslist"=>$newslist,"newslistf"=>$newslistf,"newslistt"=>$newslistt));    
     }
}
?>

Main page view:
<div class="found-news-feed">
     <h2>Новости</h2>
 
       
     
     
<!--Вся лента новостей--> 
  
   <div class="news-slide">
  <!--Контейнер с переключателями-->
     <div class="news-sliders">
       <div>
       <img src="/media/images/site/desktop/homepage/foundnewsfeed/navigate/slider/slide-back.png" />
     </div>
     <div>
       <img src="/media/images/site/desktop/homepage/foundnewsfeed/navigate/slider/slide-go.png" />
     </div>
   </div>
     <div class="news-feed-slider-cont">
         <div class="slide">
       
           
          <?php
          $newslistcont=$newslist->queryAll();
          foreach ($newslistcont as $list){ 
          ?>
  
         <div class="news">
           <?php if($list['image']!=""){ ?>
                  <div class="image" style="background-image:url('<?php echo $list['image']; ?>');">
                      &nbsp;
                  </div>
                <?php } else { ?>
                  <div class="image">
                      &nbsp;
                  </div>
                <?php } ?>
           <h2><?php echo $list['title']; ?></h2>
           <span>
               <p><?php echo $list['content']; ?></p>
           </span>
           <span style="margin-top:11px;">Добавлено <?php echo $list['date']; ?></span>
           <?php echo CHtml::link("Читать далее","/news/?view_id=". $list['id'],array()); ?>
       </div>

      <?php } ?>
    
         </div>
   
     <div class="slide desktopel">
             <?php
          $newslistcont=$newslistf->queryAll();
          foreach ($newslistcont as $list){ 
          ?>
  
         <div class="news">
           <?php if($list['image']!=""){ ?>
                  <div class="image" style="background-image:url('<?php echo $list['image']; ?>');">
                      &nbsp;
                  </div>
                <?php } else { ?>
                  <div class="image">
                      &nbsp;
                  </div>
                <?php } ?>
           <h2><?php echo $list['title']; ?></h2>
           <span>
               <p><?php echo $list['content']; ?></p>
           </span>
           <span style="margin-top:11px;">Добавлено <?php echo $list['date']; ?></span>
           <?php echo CHtml::link("Читать далее","/news/?view_id=". $list['id'],array()); ?>
       </div>

      <?php } ?>
         </div>
         <div class="slide desktopel" style="">
<!--Проблемный слайдер-->
             <?php
          $newslistcont=$newslistt->queryAll();
          foreach ($newslistcont as $list){ 
          ?>
  
         <div class="news">
           <?php if($list['image']!=""){ ?>
                  <div class="image" style="background-image:url('<?php echo $list['image']; ?>');">
                      &nbsp;
                  </div>
                <?php } else { ?>
                  <div class="image">
                      &nbsp;
                  </div>
                <?php } ?>
           <h2><?php echo $list['title']; ?></h2>
           <span>
               <p><?php echo $list['content']; ?></p>
           </span>
           <span style="margin-top:11px;">Добавлено <?php echo $list['date']; ?></span>
           <?php echo CHtml::link("Читать далее","/news/?view_id=". $list['id'],array()); ?>
       </div>

      <?php } ?>
         </div>
         
      
       
    </div>   
    
  <div class="news-slider-tabs">
<!--Вкладка-индикатор просмотра слайда-->
      <center>
       <div class="tab">
          <img src="/media/images/site/desktop/homepage/foundnewsfeed/navigate/pagination/paginate1.png" />
       </div>
       <div class="tab desktopel">
          <img src="/media/images/site/desktop/homepage/foundnewsfeed/navigate/pagination/paginate2.png" />
       </div>
       <div class="tab desktopel">
          <img src="/media/images/site/desktop/homepage/foundnewsfeed/navigate/pagination/paginate3.png" />
       </div>
    </center>
  </div>

Where everywhere newslist-Yii-parameters for individual custom sliders.
newslist and newslistf-work well. And newslistt does a poor job.
For the third slider in the query, MySQL made a LIMIT so that the first six records were not shown, and plus the last 3 so that they were displayed, and it did not work to solve this problem.
Look here and help me, please solve this problem!
How to do a proper slideshow where data is retrieved from MySQL?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2019-01-24
@seregazolotaryow64

limit(6,3)is 6 entries starting from the third, not 3 entries starting from the 6th.
https://www.yiiframework.com/doc/api/1.1/CDbComman...
similar entry Plus, it's not clear why you need 3 separate requests? Isn't it easier to select 9 records at once? What is the sacred meaning of this division?

$newslist=Yii::app()->db->CreateCommand();
         $newslistf->select("image,title,date,content,id");
         $newslistf->from("news");
         $newslistf->order("date DESC");
         $newslistf->limit(9);

and, accordingly, the output somewhere of the first three of them
for($i=0;$i<3;$i++){
    echo $newslist[$i]['some'];
}

and now from 2nd to 5th
for($k=1;$k<6;$k++){
    echo $newslist[$i]['some'];
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question