douye1876 2012-11-04 17:16
浏览 39
已采纳

使用PHP和spry或类似的东西从mysql显示两个表

I'm trying to display data from two different tables in mysql using PHP and something like spry.. Originally, I wanted to used spry tabbed panels, but I'm not sure if that's possible. I would want the tab name to be populated from one table and the contents of that tab to be populated from another table. Here's the basic html...

<div id="TabbedPanels1" class="TabbedPanels">
  <ul class="TabbedPanelsTabGroup">
    <li class="TabbedPanelsTab" tabindex="0">NAME_1 POPULATED FROM FIRST TABLE</li>
    <li class="TabbedPanelsTab" tabindex="0">NAME_2 POPULATED FROM FIRST TABLE</li>
  </ul>
  <div class="TabbedPanelsContentGroup">
    <div class="TabbedPanelsContent">
    <table border="0" cellspacing="5" cellpadding="5">
        <tr>
<!-- CONTENT POPULATED FROM SECOND TABLE!-->
          <td width="450">&nbsp;</td>
          <td width="50">&nbsp;</td>
          <td width="50">&nbsp;</td>
          <td width="50">&nbsp;</td>
          <td width="50">&nbsp;</td>
        </tr>
      </table></div>
   </div>
</div>
</div>

The problem I think I'll have is that I won't be able to connect the tabs with the content. Since the tabs are listed first in the html... then the content. I don't know if this is possible or if there is a better way.

  • 写回答

1条回答 默认 最新

  • dongpenggan6812 2012-11-06 15:30
    关注

    It depends a little on the final result you want to get. For example:

    If the only thing you want is a list of tabs taken from a table and their content completed from another DB table you just need to do 2 query, one for each table, and save the results in variables. You can then complete the HTML structure inside a variable and finally do a echo of this variable at the end.

    // $result1 has the info of the tab names.
    // $result2 has the contents of each tab.
    $final_html='<div id="TabbedPanels1" class="TabbedPanels">
                 <ul class="TabbedPanelsTabGroup">';
    
    while($row1=$result1->mysqli_fetch_array()){
         $final_html.="<li class=\"TabbedPanelsTab\" tabindex=\"0\">$row1[0]</li>";
    }
    
    $final_html.='</ul><div class="TabbedPanelsContentGroup">
                  <div class="TabbedPanelsContent">
                  <table border="0" cellspacing="5" cellpadding="5">
                  <tr>';
    
    while($row2=$result2->mysqli_fetch_array()){
         $final_html.="<td width=\"450\">$row2[0]</td>";
    }
    
    $final_html.='</tr></table></div></div></div></div>';
    
    echo $final_html;
    

    If the problem is how to make tabs work I would suggest using Jquery.

    The main idea would be to use ids based on the same variable in the tab and the tab content. For example one tab could be named 'tab1' and its contents could be named 'tab1content'.

    If you want more detail in the Jquery part please post some of your code to see how do you want these tabs to work.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么