skip to Main Content
$store="";
$store.=<tr><td>'.$row["cus_id"].'</td></tr>';

above code is no problem
but when i put if inside will come out error

$store.=<tr><td>'.if(!empty($row["cus_id"])){echo $row["cus_id"];}.'</td></tr>';

how to put if statement inside the code ?

2

Answers


  1. One of the ways is to use a function to parse the data:

    function checkdata($string1){
    
       if (!empty($string1)) {
          return $string1;
        } else {
          return "";
      }
    
    }
    

    So the code will be :

    <?php
    
    function checkdata($string1){
    
       if (!empty($string1)) {
          return $string1;
        } else {
          return "";
      }
    
    }
    
    /////////////////////////
    
    $store="";
    $store.='<tr><td>'. checkdata($row["cus_id"]) .'</td></tr>';
    
    echo $store;
    
    ?>
    

    Note: In your question. you have missed out a quotation mark in <tr><td>'

    Login or Signup to reply.
  2. if (!empty($row["cus_id"])) {
        $cusId = $row["cus_id"]);
    } else {
        $cusId = '';
    }
    
    $store .= '<tr><td>' . $cusId . '</td></tr>';
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search