I have this table:
emailtype:
emailtypeID emailtype
1 primary
2 secondary
3 old
I have this code to show emails in the input form:
$sql = "SELECT * from emailtype";
$result = $conn->query($sql);
while($row = $result->fetch_assoc()) {
echo 'Email <input type="hidden" name="emailtype[]" id="" value="' . $row["emailtypeID"] . '"/>' . $row["emailtype"];
echo '<input type="text" name="email[]" id="" /><br />'; }
GOAL:
I would like to repeat twice the emailtypeID = 2 or emailtype = secondary, so that I can enter two email addresses with the secondary ID.
Is it possible in the while loop?
Thanks!
SOLUTION:
For anybody who needs it, this is the new code as per the Marc B suggestion.
while($row = $result->fetch_assoc()) {
echo 'Email <input type="hidden" name="emailtype[]" id="" value="' . $row["emailtypeID"] . '"/>' . $row["emailtype"];
echo '<input type="text" name="email[]" id="" /><br />';
if($row["emailtype"] == 'secondario'){
echo 'Email <input type="hidden" name="emailtype[]" id="" value="' . $row["emailtypeID"] . '"/>' . $row["emailtype"];
echo '<input type="text" name="email[]" id="" /><br />';
}
}
if (id == 2) { output extra stuff }?