您好我正在尝试使用动态数据设置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);
答案 0 :(得分:1)
更简单的方法是为每个选项卡使用单独的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>
这可以解决你的问题。