简体   繁体   English

如何在mRender中使用条件:datatables php mysql

[英]how to use condition in mRender : datatables php mysql

Hi I am using datatables ,I am getting record properly but from mRender I have 3 record. 嗨,我正在使用数据表,我正在正确记录,但是从mRender我有3条记录。 I want if condition is true then only it will be shown else not . 我想如果条件为真,那么只会显示它,否则不会显示。 But it not working. 但它不起作用。

Also how can I use if condition under anchor tag of it , I means like : 另外,如果条件在其锚标签下,我该如何使用,我的意思是:

<a href="test_list.php?a='+full[20]+'&ab='+full[21]+'" class="click_'+full[22]+'">\n\
     '+full[20]+' - if (full[23] == 87 ) { '+ echo TESTER +' }  \n\  
</a>

Please note in above if condition "TESTER" is Defines a named constant 如果条件“ TESTER”为定义命名常量,请在上面注意

Below is format : 下面是格式:

$(document).ready( function() {
  var oTable = $('#example').dataTable( {
    "bProcessing": true, 
    "bServerSide": true,
    "sAjaxSource": "test_list_db.php",
    "aoColumnDefs": [ {
      "aTargets": [ 2 ],
      "mData": "null",
      "mRender": function ( data, type, full ) {

                if(full[20] != 0 ){
                var status = '<div id="container">\n\
                        <a href="test_list.php?a='+full[20]+'&ab='+full[21]+'" class="click_'+full[22]+'">\n\
                        '+full[20]+' - '+full[23]+'  \n\
                        </a><br \>\n\  </div>';

                } else if(full[21] != 0){   //  -- if this record is ZERO then will not be seen 
               var status = '<div id="container">\n\
                        <a href="test_list.php?a='+full[0]+'&ab='+full[20]+'" class="click_'+full[0]+'">\n\
                        '+full[21]+' - '+full[24]+'  \n\
                        </a><br\>\n\ </div>';
                } else if(full[22] != 0){
               var status = '<div id="container">\n\
                        <a href="test_list.php?a='+full[0]+'&ab='+full[20]+'" class="click_'+full[0]+'">\n\
                        '+full[22]+' - '+full[25]+'  \n\
                        </a><br\>\n\ </div>';
                }
  return status;

      }
    } ]
  } );
} );

please let me know where is wrong and how to use that if condition under anchor tag 请让我知道哪里出了问题以及锚标签下的条件如何使用

you try consolde.log() or alert() to check that if or else if conditions are working properly anf compiler runing inner code of if and else-if, for example 您可以尝试使用consolde.log()或alert()来检查条件是否正常运行,并且编译器运行if和else-if的内部代码,例如

if(full[20] != 0 ){
   var status = '<div id="container">\n\
      <a href="test_list.php?a='+full[20]+'&ab='+full[21]+'" class="click_'+full[22]+'">\n\
      '+full[20]+' - '+full[23]+'  \n\
       </a><br \>\n\  </div>';
   console.log(status);

}

after that check data in your browser console. 之后,在浏览器控制台中检查数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM