0

嗨,我正在尝试使用动态数据设置 spry 选项卡式面板,我想使用单个查询来完成这项工作,我只在“Tab 1”、“Tab 2”、“Tab 3”中得到结果不显示任何数据,我想我在重复区域中使用 while 循环三次使用相同的查询,这就是为什么会发生这种情况,我尝试使用 foreach 循环但没有帮助,这是我到目前为止的测试代码,请提出正确的方法这个。

谢谢。

我的 spry 选项卡式面板代码是这样的。

<div id="TabbedPanels1" class="TabbedPanels">
<ul class="TabbedPanelsTabGroup">
<li class="TabbedPanelsTab" tabindex="0">Tab 1</li>
<li class="TabbedPanelsTab" tabindex="0">Tab 2</li>
<li class="TabbedPanelsTab" tabindex="0">Tab 3</li>
</ul>
<div class="TabbedPanelsContentGroup">

<div class="TabbedPanelsContent">
<?php while ($list = mysql_fetch_assoc($queryresult)): ?>
<div class="category-main-container">
<div class="category-main-desc"> <?php echo $list['title'];?></a>
</div><!--end of category-desc-->
</div><!--end of category-container-->
<?php endwhile;?>
</div>

<div class="TabbedPanelsContent">
<?php while ($list = mysql_fetch_assoc($queryresult)): ?>
<div class="category-main-container">
<div class="category-main-desc"> <?php echo $list['id'];?></a>
</div><!--end of category-desc-->
</div><!--end of category-container-->
<?php endwhile;?>
</div>

<div class="TabbedPanelsContent">
<?php while ($list = mysql_fetch_assoc($queryresult)): ?>
<div class="category-main-container">
<div class="category-main-desc"> <?php echo $list['rating'];?></a>
</div><!--end of category-desc-->
</div><!--end of category-container-->
<?php endwhile;?>
</div>

</div>
</div>
<script type="text/javascript">
var TabbedPanels1 = new Spry.Widget.TabbedPanels("TabbedPanels1");
</script>

而php查询是这样的。

$offset = ($currentpage - 1) * $rowsperpage;
$sqlquery = "SELECT * FROM $tablename ORDER BY $orderby $sortby LIMIT $rowsperpage OFFSET $offset";
$queryresult = mysql_query($sqlquery, $connection) or trigger_error("SQL", E_USER_ERROR);
4

1 回答 1

0

更简单的方法是为每个选项卡使用单独的 MySQL 查询,如下所示

$sqlquery1 = "SELECT id FROM table_name ORDER BY id ASC";
$queryresult1 = mysql_query($sqlquery1, $connection) or trigger_error("SQL", E_USER_ERROR);
$sqlquery2 = "SELECT title FROM table_name ORDER BY id ASC";
$queryresult2 = mysql_query($sqlquery2, $connection) or trigger_error("SQL", E_USER_ERROR);
$sqlquery3 = "SELECT rating FROM table_name ORDER BY id ASC";
$queryresult3 = mysql_query($sqlquery3, $connection) or trigger_error("SQL", E_USER_ERROR);

并在选项卡式菜单中这样做。

<div class="TabbedPanelsContent">
<?php while ($list = mysql_fetch_assoc($queryresult1)): ?>
<div class="category-main-container">
<div class="category-main-desc"> <?php echo $list['id'];?></a>
</div><!--end of category-desc-->
</div><!--end of category-container-->
<?php endwhile;?>
</div>

<div class="TabbedPanelsContent">
<?php while ($list = mysql_fetch_assoc($queryresult2)): ?>
<div class="category-main-container">
<div class="category-main-desc"> <?php echo $list['title'];?></a>
</div><!--end of category-desc-->
</div><!--end of category-container-->
<?php endwhile;?>
</div>  

<div class="TabbedPanelsContent">
<?php while ($list = mysql_fetch_assoc($queryresult3)): ?>
<div class="category-main-container">
<div class="category-main-desc"> <?php echo $list['rating'];?></a>
</div><!--end of category-desc-->
</div><!--end of category-container-->
<?php endwhile;?>
</div>

这应该可以解决您的问题。

于 2012-06-08T14:40:41.077 回答