php - jquery ui 选项卡和 php 回显数据

标签 php jquery mysql html

我正在使用jquery ui's tabs

我想通过使用 php 从 mysql 数据库获取选项卡来使其动态化,但不确定如何根据我拥有的表的行数添加片段 1 , 2 , 3 。 例如,有 5 行,这意味着有 5 个片段。这是 jquery ui 的 html 代码。

<div id="featured" >
    <ul class="ui-tabs-nav">
        <li class="ui-tabs-nav-item ui-tabs-selected" id="nav-fragment-1"><a href="#fragment-1"><img class="thumb" src="http://upload.wikimedia.org/wikipedia/en/thumb/0/0f/Avs38.jpg/250px-Avs38.jpg" alt="" /><span>15+ Excellent High Speed Photographs</span></a></li>
            <li class="ui-tabs-nav-item" id="nav-fragment-2"><a href="#fragment-2"><img class="thumb" src="http://www.crunchbase.com/assets/images/original/0007/5132/75132v1.jpg" alt="" /><span>20 Beautiful Long Exposure Photographs</span></a></li>  
    </ul>
    <!-- First Content -->
    <div id="fragment-1" class="ui-tabs-panel" style="">
        <img src="image.jpg" alt="" />
        <div class="info" >
        <h2><a href="#" >Loerm Ipsum</a></h2>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla tincidunt condimentum lacus. Pellentesque ut diam....<a href="#" >read more</a></p>
        </div>
    </div>

</div>

通常我会使用这个 php 代码来回显数据库

  <?php
           $rows = array();
    while($row = mysql_fetch_array( $query )){

      $rows[] = $row;

      echo "'Some html code data $row[image] test'\n";
      }

    }

    ?>

但是如果我使用这段代码,它会生成一个像这样的html:

<div id="fragment-1" class="ui-tabs-panel" style="">
            <img src="image.jpg" alt="" />
            <div class="info" >
            <h2><a href="#" >Loerm Ipsum</a></h2>
            <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla tincidunt condimentum lacus. Pellentesque ut diam....<a href="#" >read more</a></p>
            </div>
        </div>
<div id="fragment-1" class="ui-tabs-panel" style="">
            <img src="image2.jpg" alt="" />
            <div class="info" >
            <h2><a href="#" >Loerm Ipsum2</a></h2>
            <p>L2222<a href="#" >read more</a></p>
            </div>
</div>

如您所见,它不会生成第二个片段,即片段二。

我希望结果是这样的:

<div id="fragment-1" class="ui-tabs-panel" style="">
            <img src="image.jpg" alt="" />
            <div class="info" >
            <h2><a href="#" >Loerm Ipsum</a></h2>
            <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla tincidunt condimentum lacus. Pellentesque ut diam....<a href="#" >read more</a></p>
            </div>
        </div>
<div id="fragment-2" class="ui-tabs-panel" style="">
            <img src="image2.jpg" alt="" />
            <div class="info" >
            <h2><a href="#" >Loerm Ipsum2</a></h2>
            <p>L2222<a href="#" >read more</a></p>
            </div>
</div>

那么我该怎么做呢?

最佳答案

<?php
    $rows = array();
    $frag = 1;
    while($row = mysql_fetch_array( $query )){

       $rows[] = $row;
       echo "fragment-$frag";
       echo "'Some html code data $row[image] test'\n";
       $frag++;
  }

}

?>

关于php - jquery ui 选项卡和 php 回显数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9668907/

相关文章:

javascript - Kendo UI 中添加记录功能,始终插入两行

php - 如何使用strtotime和日期获取相对于今天的上个月和年份?

jquery - toggleClass 切换页面之间给出白色闪烁

javascript - jquery不能通过函数传递变量

sql - 连接查询出现问题

php - 如何优化 SQL 查询以避免 while() 嵌套子查询?

php - Chart.js - 使用 mysql 和 php 从数据库中获取数据

php reCaptcha提交后不会返回确认

jquery - 在父框架和子 iframe 之间拖放元素

mysql更新查询set下是否可以有case语句和select语句