0

您好我想使用表格显示一些搜索结果。在我的代码中,基本详细信息显示在一个表格中,如果我们想查看更多详细信息,您必须单击查看更多选项。隐藏详细信息也显示在单独的表格中。但是我的代码有问题。如果我的数据库中有多个搜索结果,则有关第一人称的详细信息将根据需要显示。这意味着我想查看更多详细信息,我想单击查看更多,然后它会滑下隐藏表。但搜索结果的其余部分也显示隐藏的表格。而且,如果我单击其余部分的查看更多选项,它会再次滑下第一人称表的隐藏表。在这里,我附上了我的代码。你能帮我解决这个问题吗?

<body>
<div class="container"> <!-- container -->
<div class="row" id="main-content">
<div class="span8">

<div class="well">    <!-- -start of well class -->
<?php

dbConnect();

$district = $_POST['district'];
$category = $_POST['catID'];
$subject  = $_POST['subID'];

//get the category name
$get_cat_name = mysql_query("SELECT catName FROM tutor_category WHERE catID='{$category}' ");
while($row = mysql_fetch_assoc($get_cat_name ))
{
    $cat_name = $row['catName'];
}

//get the subject name
$get_sub_name = mysql_query(" SELECT subName FROM tutor_subjects WHERE catID='{$category}' AND subID='{$subject}'");
while($row = mysql_fetch_assoc($get_sub_name ))
{
    $sub_name = $row['subName'];
}
?>


<!-- ****************** Heading Table *******************-->
<table class="table table-bordered">
            <tr>
                <th> <?php echo $district." District - ". $cat_name ." - ". $sub_name ?> </th>
        </tr>
</table>            
<!-- ****************** end of heading table *******************-->


<?php
//get tutor IDs
$get_tutor_id = mysql_query(" SELECT DISTINCT tutorID FROM tutor_register_subjects WHERE district='{$district}' AND catID='{$category}' AND subID='{$subject}' ");


while($row = mysql_fetch_assoc($get_tutor_id)) // first
{
    $tutor_id = $row['tutorID'];

$query = mysql_query(" SELECT * FROM tutor WHERE tutorID='{$tutor_id}' ");

while($row = mysql_fetch_assoc($query))
{ // second 

    $fname = $row['firstName'];
    $lname = $row['lastName'];
    $nic   = $row['nic'];
  $gender = $row['gender'];
    $education = $row['education'];
    $address = $row['address'];
    $profession= $row['profession'];
    $email = $row['email'];
    $cnum = $row['contactNum'];
  $avatar = $row['avatar'];

} // second
?>
<div class="control-group">
<!-- basic details -->
<table class="table table-bordered">    

  <tr>
    <td width="120" rowspan="4"><?php echo "<img src='uploads/".$avatar."' height='120' width='100'>"?></td>
    <th width="120">Name</th>
    <td><?php echo $fname." ". $lname?></td>
  </tr>
  <tr>
    <th>NIC</th>
    <td><?php echo $nic ?></td>
  </tr>
  <tr>
    <th>Gender</th>
    <td><?php echo $gender ?></td>
  </tr>
  <tr>
    <td colspan="2"><a class="more">View More</a>&nbsp;&nbsp;&nbsp;&nbsp;<a class="less">View Less</a></td>

  </tr>
</table>
</div>
<!-- end of basic details --> 

<!-- more details-->
<div class="control-group" id="more">
<table class="table table-bordered">

 <tr>
    <th>Contact Number</th>
    <td><?php echo $cnum ?></td>

  </tr>
  <tr>
    <th>Email</th>
    <td><?php echo $email ?></td>

  </tr>
  <tr>
    <th>Address</th>
    <td><?php echo $address ?></td>

  </tr>
  <tr>
    <th>Education</th>
    <td><?php echo $education ?></td>

  </tr>
  <tr>
    <th>Work Place</th>
    <td><?php echo $profession ?></td>

  </tr>
</table>
</div>
<!-- end of more details-->    

<legend></legend>

<?php 
} // first
?>

</div> <!-- -start of well class -->    
</div> <!-- end span12 class -->
</div> <!-- end of row class -->
</div> <!-- container -->

<!-- view more script-->
<script src="../js/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#more").hide();
  $(".less").click(function(){
    $("#more").slideUp(1000);
  });
  $(".more").click(function(){
    $("#more").slideDown(1000);
  });
});
</script>

</body>
4

1 回答 1

0

发生的事情是$("#more")选择每个具有 ID 的 div 并更改它

给每个当前用户独有的东西.less.more

<div class="less" data-id="<?php echo $person_id; ?>">Show less</div>

<div class="more" data-id="<?php echo $person_id; ?>">Show more</div>

然后在你#more的实际数据所在的地方,做同样的事情

<div id="more-<?php echo $person_id; ?>">More information here</div>

现在在你的 jQuery 中,选择正确的 id:

$(".less").click(function(){
   $("#more-"+ $(this).attr('data-id')).slideUp(1000);
});
$(".more").click(function(){
    $("#more-"+ $(this).attr('data-id')).slideDown(1000);
});

您现在有效地做的是告诉 jQuery 选择 div with 例如id="more-15",以防您单击.morewith 属性data-id="15",从而选择正确的 div :)

注意:您不必使用 div 来执行此操作。这也可以解决无效的 HTML,因为您有大量具有相同 id 的元素

见:http ://ejohn.org/blog/html-5-data-attributes/

于 2013-07-24T15:43:13.730 回答