Show label data on radio instead of text

0

I have this query and I show it this way:

<?php 
if(isset($_POST['data']))
{
$servername = "xxx.xxx.x.xx";
$username = "xxxxx";
$password = "xxxxxxxx";
$dbname = "xxxxxxx";

$conn = new mysqli($servername, $username, $password, $dbname);
$conn->set_charset('utf8');

$inicio = mysqli_real_escape_string($conn, $_POST['data']);

$sql = "SELECT 'regOratorio'.'DataEntrada',
'regOratorio'.'Utente',
'regOratorio'.'Estado',
'regOratorio'.'Observacao',
'regOratorio'.'Colaborador'
FROM 'centrodb'.'regOratorio' WHERE DataEntrada = '$inicio'";

 $result=mysqli_query($conn, $sql);

if (!$result) {
  echo 'There are no results for your search';
  } else {
 echo '<form name="customer_details" action="" method="POST" onsubmit="return alguma_funcao()">';    
 }
while($row = mysqli_fetch_array($result, MYSQLI_ASSOC))
{

echo "<fieldset>";
echo "<table cellspacing='10'>";
 echo "<tr>";
echo "<td>";   

echo "<label>Utente</label>"; 
echo "<input id='' type='text' value='".$row['Utente']."'";  

echo "<label>Estado</label>"; 
echo "<input id='' type='text' value='".$row['Estado']."'";  

echo "<label>Observacao</label>"; 
echo "<input type='text' value='".$row['Observacao']."'";
echo "</td>";
echo "</tr>";
echo "</table>";
echo "</fieldset>";

echo "<fieldset>";
echo "<table cellspacing='10'>";
echo "<tr>";
echo "<td>";
echo "<input type='text' value='".$row['Colaborador']."'";
echo "</td>";
echo "</tr>";
echo "</table>";
echo "</fieldset>";

 }
echo "</form>";
mysqli_close($conn);
} 
else
{
?>

<form action="" method="post">
  <label>Enter Student Number:</label>
  <input name="data" type="date" placeholder="Type Here">
  <br>
  <br>
  <input type="submit" value="Enter">
</form>
<?php
}
?>
The State label is as type='text' , but I wanted it to show query data as type='radio' , where I have two states ( Present and > Absent ), I want you to select both and select what has been registered in the table and I want to be able to edit this field ( state ) and strong>. It's possible?

    
asked by anonymous 05.02.2018 / 12:35

1 answer

0

Well come on,

Just change this code:

echo "<label>Estado</label>"; 
echo "<input id='' type='text' value='".$row['Estado']."'";  

so:

echo "<label>Estado</label>"; 
echo "<input type='radio' value='presente' " . ( ($row['Estado']=='presente') ? 'checked' : '' ) ."> Presente";
echo "<input type='radio' value='ausente' " . ( ($row['Estado']=='ausente') ? 'checked' : '' ) ."> Ausente";

PhP allows you to write an if like this:

($row['Estado'] == ausente)?
 'checked' : ''>Ausente"

you are saying if your state ($ row ['State']) is equal to absent, then mark that radius as checked if not put nothing.

I think it's worth showing you how it would look like a select combo.

A visual example of what it would look like to select and radio

Estados com select: <br>
<select name="estados">
    <option value="sp">São Paulo</option>
    <option value="rj">Rio de Janeiro</option>
    <option value="mg">Minas Gerais </option>
</select>

<br>
<br>

Estados radio: <br>
<input type="radio" name="sp" value="sp" checked>São Paulo<br>
<input type="radio" name="rj" value="rj">Rio de Janeiro<br>
<input type="radio" name="mg" value="mg"> Minas Gerais 
    
05.02.2018 / 13:14