简体   繁体   中英

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. 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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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