如何在php循环中显示隐藏的数据类型

如何在php循环中显示隐藏的数据类型

本文介绍了如何在php循环中显示隐藏的数据类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种方法可以切换显示/隐藏以动态填充php循环中的数据?

Is there a way to toggle show/hide for data that is dynamically populated in a php loop?

我一直在尝试找出实现此目的的最佳方法,但是我只是认为我并不了解该方法,因此我不确定最佳实践是什么.

I've been around and around trying to figure out the best way to do this, but I just don't think I know enough to make this work and I'm not sure what best practice is.

这里是情况:

  1. 申请人正在通过我的网站提交摘要,并进入了数据库
  2. 管理员登录并查看提交的结果-这是一个表,其中包含一些基本信息,但没有抽象文本,因为这太长了.
  3. 我想要一个按钮(或其他按钮!)来显示/隐藏摘要文本,同时为管理员提供将摘要分配给会话的机会.
  1. Applicants are submitting abstracts via my website, and they go into a database
  2. Administrators log in, and view the submitted results- this is a table that has some of the basic information, but not the abstract text because that is too long.
  3. I would like to have a button (or something else!) that will show/hide the abstract text, along with giving the administrator the opportunity to assign the abstract to a session.

我以为我可以做一个jquery显示/隐藏按钮的事情,但是我无法使其工作.这是代码,请注意,这是全部开发过程,并非所有安全功能都在这里.我之所以这样说,是因为不可避免地会有人对会话进行评论或对字符串进行转义,等等.

I thought I could just do a jquery show/hide button thing, but I can't get it to work. Here's the code- and note this is all development and not all security features are here. I say this because there's inevitably someone that will comment on sessions or escape strings, etc.

<?php
include_once('xxx.php');
$conn = new connectorfunction();

$query = "SELECT * FROM tablename ORDER BY abstract_id";
$result = mysql_query($query);

$numfields = mysql_num_fields($result);
$data = array();
$flist = array();

for($i=0;$i<$numfields;$i++)$flist[] = mysql_field_name($result,$i);
$data[0] = $flist;
while($row = mysql_fetch_assoc($result)){
  $data[] = $row;

print '
  <tr>
   <td>
   <span style="text-decoration: underline">Author:</span>
   <br />
   ' . $row['abstract_author'] .'
   </td>

  <td>
   <span style="text-decoration: underline">Title:</span>
  ' . $row['presentation_title'] . '
  <br />
  <button>View/Assign</button>
  </td>

  <td>
  ';

  if ($row['abstract_category'] === NULL ) {
print '
      Needs Session
    ';
  }
  else {
print '
      Assigned
    ';
  }
  print'

  <tr style="display:none;">
<td colspan="3">

'. $row['abstract_text'] .'
 </tr>

 <tr style="display:none;">
   <td colspan="3">
      <form action="assign_session.php" method="post" id="form">
    <label for="abstract_category">Assign Session:
    <input type="hidden" name="abstract_id" value="'. $row['abstract_id'] .'" />
    <input type="radio" name="abstract_category" value="session1" />Session One
    <input type="radio" name="abstract_category" value="session2" />Session Two
    <input type="radio" name="abstract_category" value="notapplicable" />Not Applicable
 <button type="submit" formaction="assign_session.php">Assign</button></label>
 </form>

   </td>
  </tr>
  ';
 }
 ?>

因此您可以看到,有一个按钮:<按钮>查看/分配< /按钮>

So you can see, there's a button: < button >View/Assign< / button >

有两个< tr>为显示:无"样式.

And there are the two < tr > with the "display: none" style.

该表在填充时看起来真的很棒,我只需要管理员一种很好的方法来查看抽象文本,但是我似乎无法成功指向php中的jquery函数.关于解决此问题的最佳方法有什么建议吗?

The table looks really great when it is populated, I just need a good way for the admins to see the abstract text, but I don't seem to be able to successfully point to jquery functions within php. Any advice on the best way to handle this?

推荐答案

是这样的吗? 演示

 example:<br />
    <button onClick="$('.hide').toggle();">click me</button>
    <table>
         <tr style="display:none;" class="hide">
            <td colspan="3">abstract text</td>
         </tr>

         <tr style="display:none;" class="hide">
           <td colspan="3">
              <form action="assign_session.php" method="post" id="form">
                <label for="abstract_category">Assign Session:</label>
                <input type="hidden" name="abstract_id" value="'. $row['abstract_id'] .'" />
                <input type="radio" name="abstract_category" value="session1" />Session One
                <input type="radio" name="abstract_category" value="session2" />Session Two
                <input type="radio" name="abstract_category" value="notapplicable" />Not Applicable
                 <button type="submit" formaction="assign_session.php">Assign</button></label>
             </form>
        </td>
      </tr>
    </table>

我使用jquery来切换(显示/隐藏)您需要显示/隐藏的元素.

I use jquery to toggle (show/hide) the elements you need to show/hide.

此外,您在此代码上有一些错误(例如您没有关闭第一个td,没有使用正确的标签).

Moreover you have several errors on this code (like you are not closing the first td, not using in the right way labels).

这篇关于如何在php循环中显示隐藏的数据类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 00:23