PHP中的搜索条件

时间:2012-08-09 06:28:46

标签: php javascript jquery

JAVASCRIPT

function ShowContent(id) {
if(id.length < 1) { return; }
document.getElementById(id).style.display = "block";
}

PHP

$test = mysql_query('SELECT userid,testid,testname FROM test_table WHERE userid = 9 ORDER BY name');
TestName : <select>
             while($row=mysql_fetch_array($test))
             {
                $testname = $row['testname']; 
                $testid   = $row['testid'];
                echo '<option value='.$testid.'>'.$testname.'</option>
             }
           </select>
   echo '<div id="testid" style="display:none;">
      echo '<table>
             <tr><th>USERID</th</tr>
             <tr><th>TESTNAME</th></tr> 
             <tr><th>MARKS</th></tr>
      publishtest = mysql_query('SELECT id,userid,publishtest,marks FROM publish_table WHERE userid= 9 GROUP BY id');
      while($row=mysql_fetch_array($publishtest))
      {
        $userid = $row['userid'];
        $testid = $row['id']; /*This is test id*/
        $testname = $row['publishtest']; /* This is test name*/
        $marks = $row['marks'];
        echo '<tr><td>'.$userid.'</td>
                <td>'.testid.'</td>
                <td>'.testname.'</td>
                <td>'.$marks.'</td>
            </tr> 
      }
        echo '</table>';
        echo '</div>';

当我从select标签中选择test时,我需要显示该testid的div。我想要在javascript,jquery

1 个答案:

答案 0 :(得分:0)

你可以试试这个:

<强>的JavaScript

$('#showDivSelect').change(function (e) {
    var divId = $(this).children('option:selected').val();
    $('#' + divId).css('display', 'block');
});​

<强> HTML

<select id="showDivSelect">
<option id="o1">Div1</option>
<option id="o2">Div2</option>
</select>
<div id="Div1"></div>
<div id="Div2"></div>​

<强> CSS

#Div1 {
    width: 30px;
    height: 30px;
    background-color: red;        
    display: none;
}
#Div2 {
    width: 30px;
    height: 30px;
    background-color: blue;
    display: none;    
}​

以下是工作示例:http://jsfiddle.net/ePSDu/