PHP - Puedo colocar un if en while mientras imprime datos de BD

 
Vista:

Puedo colocar un if en while mientras imprime datos de BD

Publicado por Julio (2 intervenciones) el 16/01/2019 00:31:46
Me gustaria saber si hay alguna manera de colocar un if en while mientras imprime datos de BD

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
if ($resultado->num_rows > 0) {
    $salida.="<table class='tabla_datos'>
        <thead>
            <tr>
            <th colspan='8'>Lista de Clientes</th>
            </tr>
        </thead>

        <tbody>
            <tr>
                <th>Nombre</th>
                <th>Identificacion</th>
                <th>Telefono</th>
                <th>Sexo</th>
                <th >N° Compras</th>
                <th >Agregado</th>
                <th>Actualizar</th>
                <th >Eliminar</th>
            </tr>
        ";
 
 
    while ($fila= $resultado->fetch_assoc()) {
        $salida.="<tr>
            <td>".$fila['Nombre']."</td>
            <td>".$fila['Identificacion']."</td>
            <td>".$fila['Telefono']."</td>
            <td>".$fila['Sexo']."</td>
            <td >".$fila['Ncompras']."</td>
            <td >".$fila['Fecha']."</td>
            <td ><a href='actualizar_cliente.php?id=".$fila['id']."'></a></td>".
            //ME GUSTARIA COLACAR EL IF AQUI, Y SEGUN SE CUMPLA LA CONDICION 
                                IMPRIMA LA SIGUIENTE LINEA:
            "<td ><a href='eliminar_cliente.php?id=" .$fila['id']."'></a></td>"
 
        "</tr>";
    }
 
$salida.="</tbody></table>";
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de xve
Val: 3.943
Oro
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

Puedo colocar un if en while mientras imprime datos de BD

Publicado por xve (6935 intervenciones) el 16/01/2019 08:49:56
Segun entiendo, seria algo así:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
while ($fila= $resultado->fetch_assoc()) {
    $salida.="<tr>
        <td>".$fila['Nombre']."</td>
        <td>".$fila['Identificacion']."</td>
        <td>".$fila['Telefono']."</td>
        <td>".$fila['Sexo']."</td>
        <td >".$fila['Ncompras']."</td>
        <td >".$fila['Fecha']."</td>
        <td ><a href='actualizar_cliente.php?id=".$fila['id']."'></a></td>";
 
    if(....)
    {
        $salida.="<td ><a href='eliminar_cliente.php?id=" .$fila['id']."'></a></td>";
    }
 
    $salida.="</tr>";
}
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Puedo colocar un if en while mientras imprime datos de BD

Publicado por Julio (2 intervenciones) el 17/01/2019 22:57:45
Muchísimas gracias, me ha servido tu aporte.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar