使用jquery在php循环中隐藏整个tr行?

时间:2014-10-02 10:10:00

标签: javascript php jquery

如果td输入的值为0,我试图在我的php循环中隐藏整个tr行。脚本在这里工作:http://jsfiddle.net/jmg2u98a/3/但是使用php循环它只是隐藏所有问题而我不知道为什么?

<script>
$(document).ready(function () {
 $(".btn1").click(function () {
   $(".hide-also").each(function(){
    if($(this).find("td input").val()==0)
      $(this).hide();
  });

 });
 $(".btn2").click(function () {
   $('td:has(input[value=0]), .hide-also').show();
 });
});
<script>

<button class="btn1">Hide</button>
<button class="btn2">Show</button>

<?php
$vals=array(0,1,2);
$result = @mysqli_query($con, $query);
if ($result) {
  while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
    $body = $row['question_body'];
    $question_id = $row['question_id'];

    echo '<tr class="hide-also">
    <td class="question">'.$body.'</td>';
    foreach($vals as $x){
      $s='';
      if($x==$row['answer_value']){
        $s="checked";
      }
      echo '<td class="answer"><input type="radio" name="answer_value['.$question_id.']" value="'.$x.'" '.$s.'></td>';
    }
    echo '</tr>';
  }
}
?>

db:
questions
question_id question_body
    1         Question1
    2         Question2
answers
question_id answer_value
    1            0
    2            1

我使用连接来获取question_id question_body answer_value来输出。

SELECT answers.question_id, question_body, answer_value FROM answers LEFT JOIN questions on answers.question_id = questions.question_id where question_sort=1 AND form_id=$formid

0 个答案:

没有答案