How can I show my active or inactive status in php?

1

  

The code. I would like instead of 1 and 0, it shows Active or Inactive. I would appreciate your help.

$cadena .= '
    <table class="table table-bordered table-hover">
        <thead>
            <th class="col-sm-2">CODIGO</th>
            <th class="col-sm-2">NOMBRE</th>
            <th class="col-sm-2">TELEFONO</th>
            <th class="col-sm-2">DIRECCION</th>
            <th class="col-sm-1">ACTIVO </th>
            <th class="col-sm-1">CONTRIBUYENTE </th>
            <th class="col-sm-1">EDITAR</th>
            <th class="col-sm-1">BORRAR</th>
        </thead>
        <tbody>';
        while ($fila = $establecimientos->fetch_array()) {
             $cadena .= '
                <input type="hidden" id="nombre'.$fila['idpuntoestablecimiento'].'" value="'.$fila['nombre'].'">
                <input type="hidden" id="telefono'.$fila['idpuntoestablecimiento'].'" value="'.$fila['telefono'].'">
                <input type="hidden" id="direccion'.$fila['idpuntoestablecimiento'].'" value="'.$fila['direccion'].'">
                <input type="hidden" id="activo'.$fila['idpuntoestablecimiento'].'" value="'.$fila['activo'].'">
                <input type="hidden" id="idContribuyente'.$fila['idpuntoestablecimiento'].'" value="'.$fila['idContribuyente'].'">
                <tr>
                    <td class="info">'.$fila['idpuntoestablecimiento'].'</td>
                    <td class="success">'.$fila['nombre'].'</td>
                    <td class="success">'.$fila['telefono'].'</td>
                    <td class="success">'.$fila['direccion'].'</td>

                    <td>
                        if($fila['activo']==1){
                            echo $act='ACTIVO';
                        } else {
                            echo $act='INACTIVO';
                        }
                    </td>

                    <td class="success">'.$fila['razonsocial'].'</td>
                    <td>
                        <input type="button" class="btn btn-primary" id="editarEstablecimiento" data-target="#eModalEstablecimiento" data-toggle="modal" value="editar" onclick="editarEstablecimiento('.$fila['idpuntoestablecimiento'].')">
                    </td>
                    <td>
                        <input type="button" onclick="borrarEstablecimiento('.$fila['idpuntoestablecimiento'].')" class="btn btn-danger" id="borraEstablecimiento" value="borrar">
                    </td>                       
                </tr>';
  

Parse error: syntax error, unexpected 'active' (T_STRING) in C: \ xampp \ htdocs \ Restaurant \ php \ paginacionestablecimientos.php on line 53

    <td class="info">'.$fila['idpuntoestablecimiento'].'</td>
                    <td class="success">'.$fila['nombre'].'</td>
                    <td class="success">'.$fila['telefono'].'</td>
                    <td class="success">'.$fila['direccion'].'</td>

                    <td>
                        if($fila['activo']==1){
                            echo $act='ACTIVO';
                        } else {
                            echo $act='INACTIVO';
                        }
                    </td>

                    <td class="success">'.$fila['razonsocial'].'</td>
    
asked by Alexis 17.10.2018 в 15:38
source

2 answers

1

You have to do the if before calling the variable $ string and then you embed it in that table like this:

while ($fila = $establecimientos->fetch_array()) {

  if($fila['activo']==1){
    $act='ACTIVO';
  } else {
    $act='INACTIVO';
  }

   $cadena .= '<input type="hidden" id="nombre'.$fila['idpuntoestablecimiento'].'" value="'.$fila['nombre'].'">
               <input type="hidden" id="telefono'.$fila['idpuntoestablecimiento'].'" value="'.$fila['telefono'].'">
               <input type="hidden" id="direccion'.$fila['idpuntoestablecimiento'].'" value="'.$fila['direccion'].'">
               <input type="hidden" id="activo'.$fila['idpuntoestablecimiento'].'" value="'.$fila['activo'].'">
               <input type="hidden" id="idContribuyente'.$fila['idpuntoestablecimiento'].'" value="'.$fila['idContribuyente'].'">
                <tr>
                    <td class="info">'.$fila['idpuntoestablecimiento'].'</td>
                    <td class="success">'.$fila['nombre'].'</td>
                    <td class="success">'.$fila['telefono'].'</td>
                    <td class="success">'.$fila['direccion'].'</td>
                    <td>'.$act.'</td>
                    <td class="success">'.$fila['razonsocial'].'</td>

In the end it would look like this:

<td>'.$act.'</td>
    
answered by 17.10.2018 / 15:49
source
1

You are alternating between a string (string) and php statements, you should try something like that, use ternary operator for the sake of simplicity

$cadena .= '
<table class="table table-bordered table-hover">
    <thead>
        <th class="col-sm-2">CODIGO</th>
        <th class="col-sm-2">NOMBRE</th>
        <th class="col-sm-2">TELEFONO</th>
        <th class="col-sm-2">DIRECCION</th>
        <th class="col-sm-1">ACTIVO </th>
        <th class="col-sm-1">CONTRIBUYENTE </th>
        <th class="col-sm-1">EDITAR</th>
        <th class="col-sm-1">BORRAR</th>
    </thead>
    <tbody>';
    while ($fila = $establecimientos->fetch_array()) {
         $cadena .= '
            <input type="hidden" id="nombre'.$fila['idpuntoestablecimiento'].'" value="'.$fila['nombre'].'">
            <input type="hidden" id="telefono'.$fila['idpuntoestablecimiento'].'" value="'.$fila['telefono'].'">
            <input type="hidden" id="direccion'.$fila['idpuntoestablecimiento'].'" value="'.$fila['direccion'].'">
            <input type="hidden" id="activo'.$fila['idpuntoestablecimiento'].'" value="'.$fila['activo'].'">
            <input type="hidden" id="idContribuyente'.$fila['idpuntoestablecimiento'].'" value="'.$fila['idContribuyente'].'">
            <tr>
                <td class="info">'.$fila['idpuntoestablecimiento'].'</td>
                <td class="success">'.$fila['nombre'].'</td>
                <td class="success">'.$fila['telefono'].'</td>
                <td class="success">'.$fila['direccion'].'</td>

                <td>'.echo ($fila["activo"]==1) ? "ACTIVO" : "INACTIVO".'</td>

                <td class="success">'.$fila['razonsocial'].'</td>
                <td>
                    <input type="button" class="btn btn-primary" id="editarEstablecimiento" data-target="#eModalEstablecimiento" data-toggle="modal" value="editar" onclick="editarEstablecimiento('.$fila['idpuntoestablecimiento'].')">
                </td>
                <td>
                    <input type="button" onclick="borrarEstablecimiento('.$fila['idpuntoestablecimiento'].')" class="btn btn-danger" id="borraEstablecimiento" value="borrar">
                </td>                       
            </tr>';
    
answered by 17.10.2018 в 15:53