2012-04-16 135 views
1

我有过滤系统的问题,我想过滤通知。过滤应该使用每个帖子都有的状态ID,例如错误报告的状态ID为nro。 6.使用下拉选择过滤信息

这是jQuery脚本使用:

$(document).ready(function() { 
$("#status_option").change(              
    function(){ 
     var statusValue = $('#status_option option:selected').val(); 
     if(statusValue == "1"){ 
      <?php 
       $sql_status1="SELECT * FROM notice, user, status WHERE notice.userID = user.userID AND notice.statusID = status.statusID = '1' ORDER BY noticeID DESC"; 
       $result_status1=mysql_query($sql_status1); 
      ?> 
     } 
     else if(statusValue == "2"){ 
      <?php 
       $sql_status2="SELECT * FROM notice, user, status WHERE notice.userID = user.userID AND notice.statusID = status.statusID AND status.statusID = '2' ORDER BY noticeID DESC"; 
       $result_status2=mysql_query($sql_status2); 
      ?> 
     }          
     else if(statusValue == "3"){ 
      <?php 
       $sql_status3="SELECT * FROM notice, user, status WHERE notice.userID = user.userID AND notice.statusID = status.statusID AND status.statusID = '3' ORDER BY noticeID DESC"; 
       $result_status3=mysql_query($sql_status3); 
      ?> 
     } 
     else if(statusValue == "4"){ 
      <?php 
       $sql_status4="SELECT * FROM notice, user, status WHERE notice.userID = user.userID AND notice.statusID = status.statusID AND status.statusID = '4' ORDER BY noticeID DESC"; 
       $result_status4=mysql_query($sql_status4); 
      ?> 
     } 
     else if(statusValue == "5"){ 
      <?php 
       $sql_status5="SELECT * FROM notice, user, status WHERE notice.userID = user.userID AND notice.statusID = status.statusID AND status.statusID = '5' ORDER BY noticeID DESC"; 
       $result_status5=mysql_query($sql_status5); 
      ?> 
     }         
     else if(statusValue == "6"){ 
      <?php 
       $sql_status6="SELECT * FROM notice, user, status WHERE notice.userID = user.userID AND notice.statusID = status.statusID AND status.statusID = '6' ORDER BY noticeID DESC"; 
       $result_status6=mysql_query($sql_status6); 
      ?> 
     } 
     else{ 
      <?php 
       $sql_default="SELECT * FROM notice, user, status WHERE notice.userID = user.userID AND notice.statusID = status.statusID ORDER BY noticeID DESC"; 
       $result_default=mysql_query($sql_default); 
      ?> 
     } 
    } 
);}); 

状态从下拉列表中选择:

<select id="status_valinta" style="width:210px" > 
<option title="css/msdropdown_img/status_all.gif">All posts</option> 
<option value="1" title=".../status1.gif">Notification</option> 
<option value="2" title=".../status2.gif">Waiting for answer</option> 
<option value="3" title=".../status3.gif">Guide</option> 
<option value="4" title=".../status4.gif">Document</option> 
<option value="5" title=".../status5.gif">Image</option> 
<option value="6" title=".../status6.gif">Bug-report</option> 

的问题是,当我选择的状态我从想要下拉没有任何反应。此外,这个过滤系统应该通过动态地在同一页面中打开过滤的信息来工作。

这是显示的打印数据是:

<table width="100%" id="notices" class="ui-widget ui-widget-content"> 
    <thead> 
     <tr class="ui-widget-header "> 
      <th>Subject</th> 
      <th>Sender</th> 
      <th>Comments</th> 
      <th>Timestamp</th> 
     </tr> 
    </thead> 
    <tbody> 
     <?php 
      while($rows=mysql_fetch_array($result)){ // Starting looping rows 
     ?> 
      <tr style="background-color:<?php echo $rows['colorCode']; ?>"> 
       <td> 
        <a class="opener_notice, load_data" href="notice_v2.php?id=<?php echo $rows['noticeID']; ?>"> 
        <?php echo $rows['title']; ?> 
       </td> 
       <td><?php echo $rows['firstname']; ?> <?php echo $rows['lastname']; ?> 
       </td> 
       <td><?php echo $rows['commentID']; ?></td> 
       <td><?php echo date('d.m.Y, H:i:s', strtotime($rows['sendTime'])); ?> 
       </td> 
      </tr> 
     <?php 
      // Stopping the looping and closing the mysql connection 
      } mysql_close(); 
     ?> 
    </tbody> 
</table>  
+0

达到什么你显然不知道这是多么可怕。 MVC的一部分,是从视图写入中删除任何和所有数据库调用。如果你继续这样,你的网站将是主要不安全的,只是fyi。 – SpYk3HH 2012-04-16 14:12:11

回答

0

你应该检查HTML页面的源你工作.... COS,因为我可以看到和理解所有的PHP代码写这里,在这个片段将在服务器上执行仅在jQuery的filteration只会有空格..

虽然你婉实现可以通过这样的

$(document).ready(function() { 
<?php     // this code will be executed on the server 
    $sql_status1="SELECT status_id, status_value FROM notice, user, status WHERE notice.userID = user.userID AND notice.statusID = status.statusID ORDER BY noticeID DESC"; // considering status_id, status_value are the required attributes 
    $result_status1=mysql_query($sql_status1); 
    foreach(result_status1 as $res) 
     $json_obj_arr[$res[status_id]] = $res[status_value] 
    echo 'var notices = '.json_encode($json_obj_arr).';'; //and we will have a json abject in our html 
?> 
var notice_json = $.parseJSON(notices);  //we will parse this object 
$("#status_option").change(              
    function(){ 
     var statusValue = $('#status_option option:selected').val(); 
     alert(notice_json.statusValue); //and directly access the value corresponding to statusValue in the notice_json object 
    }) //end on change 
})// end document.ready 
+0

做了这项工作? – 2012-04-16 19:53:19

+0

我试过了你的建议,但没有奏效。我对json没有太多的知识,但是我试图调整你的代码而没有成功。在你的代码中有值status_id和status_value,但我只有statusID,并且它被用作id =“status_valinta”中值的编号。 – user1174455 2012-04-16 22:54:42

+0

那么当用户选择某个值时你想要提醒什么? – 2012-04-17 07:31:46

相关问题