Hello, i need to get onlyone value from the second select, in the select case of the table, primo for the only 1° case td and the others blank, secondo for the 2° and other blank etc..one selection for each. Someone can help me please.?

<html>
	
	<body bgcolor="white">
	
   <font face='courier'>
	<font color='red'>
	
	<form action='test.php' method='GET'>
<select id="op" name="ops">
<option value="">seleziona....</option>
<option value="a">a</option>
<option value="b">b</option>
<option value="c">c</option>
<option value="d">d</option>
</select>

		<div class="input"><input type="text" name="nbusta" value="" id="input_nbusta" />
	</div>

<select id="tipo" name="tipos">
<option value="">Seleziona...</option>
<option value="primo">primo</option>
<option value="secondo">Secondo</option>
<option value="cambio">Cambio</option>

</select>

	
	<hr/><br/><br/>
	<input type='submit' value='vai'>
	<input type='reset' value='Reset'>
	</form>
	</body>
</html> 

//test.php

<html>
<meta charset="UTF-8">
<head></head>
<body bgcolor='white'>
	
<font face='Courier'>
<font color='red'>
<br><br>
<hr size=2>
<?php
     $date=date('d M Y');
     $nome=$_GET['ops'];
     $nbusta=$_GET['nbusta'];
     $primo=$_GET['tipos'];
     $secondo1=$_GET['secondo1'];
     $cambio2=$_GET['tipos'];
     
    //prima riga Gialla della tabella: Descrizione
    echo date('d M Y');
    echo "<br><br><hr>";
    echo "<table border=1>";
    echo "<tr bgcolor='yellow' align='center'>";
    	echo "<td>Data</td>";
    	echo "<td>Operatore</td>";
        echo "<td>N°Busta</td>";
	echo "<td>1°st</td>";
	echo "<td>2°nd</td>";
	echo "<td>3°</td>";
	
    echo "</tr>";
    
        {
	echo "<tr bgcolor='white' align='center'>";
        echo "<td>$date</td>";
    	echo "<td>$nome</td>";
	echo "<td>$nbusta</td>";
	echo "<td>$primo</td>";
        echo "<td>$secondo</td>";
        echo "<td>$cambio</td>";
        
         }
 
?>
<br><br><hr>
<center>
</body>
</html>

$_GET['tipos'] will either be - "", "primo", "secondo", or "cambio".

You can see what the submitted data is by using -

echo '<pre>'; print_r($_GET); echo '</pre>';

You would use conditional logic to test what value $_GET[‘tipos’] is to produce each of the <td></td> elements with either the value you want or an empty string.

Php has a ternary operator that can be used to write simple if/else logic in-line.

Based on what I think you are trying to do, I would use -

echo "<td>".($_GET['tipos'] == "primo" ? $_GET['tipos'] : '')."</td>";
echo "<td>".($_GET['tipos'] == "secondo" ? $_GET['tipos'] : '')."</td>";
echo "<td>".($_GET['tipos'] == "cambio" ? $_GET['tipos'] : '')."</td>";

Ok!! Thank you a lot!!
:grinning:

But if i want to print “1” like quantity 1 instead primo, secondo and cambio? Like this picture

One would hope that you would examine the code and learn how it works, so that if you want to change the value that gets used you can do so yourself. The documentation for the ternary operator can be found at this link - PHP: Comparison - Manual

Sponsor our Newsletter | Privacy Policy | Terms of Service