0
echo 'Qname : <select id ="selector">';
$s = mysql_query('SELECT qid,qname FROM q_table ORDER BY qname');
while($row = mysql_fetch_array($s))
{
  $filter = $row['qname'];
  $filterid = $row['qid']; 
  echo '<option value='.$filterid.'>'.$filter.'</option>';

echo '</select>';

echo '<div id='.$filterid.' class="colors" style="display:none;">';
echo '<table>
            <tr><th>USERID</th>
                <th>QNAME</th>
            </tr>';
$publishedqnames = mysql_query('SELECT qid, qname, quserid FROM pub_q'); 
while($row = mysql_fetch_array($publishedqnames))
{
   $qid = $row['qid'];
   $qname = $row['qname'];
   $quserid = $row['quserid'];
   echo '<tr>
            <td>'.$quserid.'</td>
            <td>'.qname.'</td> 
         </tr>';
}
echo '</table></div>';
}

当我选择 qname 时,该选定过滤器的 div(过滤器和 qname 相同)需要显示 JQUERY FILE

   $(function() 
{
    $('#selector').change(function(){
        $('.colors').hide();
        $('#' + $(this).val()).show();
    });
});

现在我无法用正确的 div 显示正确的 qid

4

1 回答 1

-1

尝试这个

echo 'Qname : <select id ="selector">';
$s = mysql_query('SELECT qid,qname FROM q_table ORDER BY qname');
while($row = mysql_fetch_array($s))
{
    $filter = $row['qname'];
    $filterid = $row['qid']; 
    echo '<option value='.$filterid.'>'.$filter.'</option>';
}
echo '</select>';
?>
<script>
 $(function() 
{
    $('#selector').change(function(){
        $('.colors').hide();
        $('#' + $(this).val()).show();
    });
});

</script>
<?php

echo '<table>
            <tr><th>USERID</th>
                <th>QNAME</th>
            </tr>';
$publishedqnames = mysql_query('SELECT qid, qname, quserid FROM pub_q'); 
while($row = mysql_fetch_array($publishedqnames))
{
   $qid = $row['qid'];
   $qname = $row['qname'];
   $quserid = $row['quserid'];
   echo '<div id='.$filterid.' class="colors" style="display:none;">';
   echo '<tr>
            <td>'.$quserid.'</td>
            <td>'.qname.'</td> 
         </tr>';
   echo '</div>';
}
echo '</table>';

如果不工作,请告诉我

于 2012-08-12T15:35:50.797 回答