2
I want to make a datalist field where the user can type to find what they want faster, but I do not want the user to be able to put something outside the suggested values, so I am using Pattern, but the code is not working and I could not find the reason.
<?php
$select = "SELECT cod_categoria, desc_categoria
FROM categoria
ORDER BY cod_categoria";
$result = $mysqli->query($select);
echo "<input list='categoria' name='cat_prod' class='form-control' pattern='";
while($row = $result->fetch_assoc()){
echo "".$row['desc_categoria']."|";
}
echo "' required>";
echo "<datalist id='categoria'>";
while($row = $result->fetch_assoc()){
echo "<option value=".$row['desc_categoria']."/>";
}
echo "</datalist>";
?>
Another question is regarding the second while, I want you to repeat the same amount of times as the first, could put just while($Row){ } ?
Thank you very much, I had already done with the select that I knew worked, as in your first example. But I tested the second example using foreach and implode and it worked. The problem was just the lack of ""'separators.
– Luigi Azevedo