Send checkbox value to a database and an icon to a table

0

My question is when doing the checkbox, everything is fine, these checkboxes are in addcliente.php:

<input type="hidden" name="Cl" value="0">
<input type="checkbox" name="Cl" value="1" />
   <label> &nbsp; Cliente </label>

<br>

<input type="hidden" name="Prov" value="0">
<input type="checkbox" name="Prov" value="1" />

<label> &nbsp; Proveedor </label>

<br>

<input type="hidden" name="Des" value="0">
<input type="checkbox" name="Des" value="1"  />
<label> &nbsp; Destinatario </label>

 </div>
</div>

As you can see I make two input since at the moment not selecting the checkbox automatically sends the value 0 and on the other hand if the value 1 is selected it sends that value to the database, all right until then the question is that I would like receive in this other page called client.php to decide if it is value is 0 send an icon of an "x" to a table class that I have in client.php and if it is okay to send a "✔" I plan to use the glyphicon, in the following code, I show the data of the mysql table as a store within each cell of the table class of the client.php page

 <tr>

<td class="text-center"><?php echo remove_junk($cliente['cliente']); ?>
?>
</td>

<td class="text-center"> <?php echo remove_junk($cliente['proveedor']); ?> 
</td>

<td class="text-center"> <?php echo remove_junk($cliente['destinatario']);? 
> 
</td>

What I still can not do is a type of condition in which verify that if the stored in the mysql table is "1" send "✔" to the table of client.php and that when it is a "0" Send "x" to the same client table.php.

<tbody> 
<?php foreach ($clientes as $cliente):?> 
<tr> 
<td class="text-center"> <?php echo remove_junk($cliente['cliente']); ?> 
</td> 
<td class="text-center"> <?php echo remove_junk($cliente['proveedor']); ?> 
</td> 
<td class="text-center"> <?php echo remove_junk($cliente['destinatario']);?> 
</td> 
</tr> 
<?php endforeach; ?> 
</tbody>

This is the code I use to fill the table I have made in client.php

 <table class="table table-bordered"> 
 <thead> 
 <tr> 
 <th class="text-center" style="width: 10%;"> Cliente </th> 
 <th class="text-center" style="width: 10%;"> Proveedor </th> 
 <th class="text-center" style="width: 10%;"> Destinatario </th> 
 </tr> 

This is the table that I mention that I have in client.php where the data I commented earlier goes.

I hope I have expressed myself well and I appreciate any help you can give me to have a good day.

Good morning, try with this code:

<?php if ($cliente['cliente'] == 1) echo "Tu código con el icono ✔" ?> 

and thanks to this code it worked but only when the checkbox is pressed but it does not send me anything when said checkbox is not pressed I want to believe that it is because I need the other condition but I already probe with else and nothing

    
asked by Guillermo Mireles 31.05.2018 в 21:00
source

1 answer

0

When extracting data from your database you can simply check them with if ... else .

<?php
if ($cliente['cliente'] == 1) {
    ?><td class="text-center">//Tu código con el icono ✔</td><?
} else {
    ?><td class="text-center">//Tu código con el icono X</td><?
}
?>

If the result is 1, then the HTML code with which you show the ✔ icon will be used, otherwise the other one will be used.

    
answered by 31.05.2018 в 21:10