加载并创建javascript循环

时间:2012-12-05 09:51:42

标签: php javascript sql yii

我在清晰的php中创建了图像滑块并且它已经工作了。但当我在Yii图像下更改它时未加载因为: - java脚本块不加载图像编号。 - 我不知道如何在yii中加载带有变量变量的javascript块,如php

档案:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
 <head>
  <title>jquery sliders</title>
  <link rel="stylesheet" href="style.css" type="text/css" media="screen" />
  <script type="text/javascript">var _siteRoot='index.html',_root='index.php';</script>
  <script type="text/javascript" src="js/jquery.js"></script>
  <script type="text/javascript" src="js/scripts.js"></script>
  <script type="text/javascript" src="jquery-1.4.2.min.js"></script>

<script type="text/javascript" src="newscript.js"></script>
 </head>
 <body>

  <!--/top-->
  <div id="header"><div class="wrap">
   <div id="slide-holder">
<div id="slide-runner">
<?php
            include("samiloxide.php");
//if(!$_POST['page']) die("0");


$section=intval($_GET['section']);

$i=1;
$j=array();

$sql=mysql_query(" select * from images order by section ");



while($rr=mysql_fetch_array($sql)){
  echo    "<a href=''><img id='slide-img-$i' src='$rr[image]' class='slide' alt='' /></a>";
       $j[]=$i;

       $i=$i+1;





        }     
   ?>



    <div id="slide-controls">
     <p id="slide-client" class="text"><strong>post: </strong><span></span></p>
     <p id="slide-desc" class="text"></p>
     <p id="slide-nav"></p>


    </div>
</div>

    <!--content featured gallery here -->
   </div>
   <script type="text/javascript">
    if(!window.slider) var slider={

    };
     slider.data=[
    <?php 
  foreach($j as $value){    

echo  "   
  { 'id':'slide-img-$value',
    'client':'First one ',
    'desc':'nature beauty photography'},
   " ;
   }  
   ?>


   ];
   </script>
  </div></div><!--/header-->
 </body>
</html>

我需要更改javascript:

<script type="text/javascript">
        if(!window.slider) var slider={

        };
         slider.data=[
        <?php 
      foreach($j as $value){    

    echo  "   
      { 'id':'slide-img-$value',
        'client':'Some text  ',
        'desc':'image description '},
       " ;
       }  
       ?>


       ];
       </script>

在Yii下工作?

1 个答案:

答案 0 :(得分:1)

试试这个,

echo '<a href="#"><img id="slide-img-', $i, '" src="', $rr['image'], '" class="slide" alt="" /></a>';