The below mysqli query will always pull one result. However, after looking at my code I feel there must be a better way to simplify the status dropdown html section. As you can see I have a bunch of if statements and an array. I done it like that so that I can set selected
in the html as the current dropdown view. Can anyone help me to make this simpler?
$query = mysqli_query($mysqli, "SELECT * From referrals WHERE id = '".$edit."';");
while($row = mysqli_fetch_array($query))
{
$editstatus = $row['status'];
}
if($editstatus == "N")
{
$estatus = "N/A";
}
if($editstatus == "I")
{
$estatus = "Installation Comp";
}
if($editstatus == "SI")
{
$estatus = "Site Inspection";
}
if($editstatus == "S")
{
$estatus = "Sold";
}
if($editstatus == "C")
{
$estatus = "Cancelled";
}
if($editstatus == "P")
{
$estatus = "Press/Follow-Up";
}
if($editstatus == "W")
{
$estatus = "Being Installed";
}
$bstatus[] = "N/A";
$bstatus[] = "Installation Comp";
$bstatus[] = "Site Inspection";
$bstatus[] = "Sold";
$bstatus[] = "Cancelled";
$bstatus[] = "Press/Follow-Up";
$bstatus[] = "Being Installed";
?>
<div class="status"><label for="edit_status">Edit Status</label>
<select id="edit_status" name="edit_status">
<?php
foreach($bstatus as $cstatus) {
if($cstatus == "N/A")
{
$dstatus = "N";
}
if($cstatus == "Installation Comp")
{
$dstatus = "I";
}
if($cstatus == "SI")
{
$dstatus = "Site Inspection";
}
if($cstatus == "Sold")
{
$dstatus = "S";
}
if($cstatus == "Cancelled")
{
$dstatus = "C";
}
if($cstatus == "Press/Follow-Up")
{
$dstatus = "P";
}
if($cstatus == "Being Installed")
{
$dstatus = "W";
}
?>
<option <?php if($cstatus == $estatus) { echo "selected=\"selected\""; } ?> value="<?php echo $dstatus; ?>"><?php echo $cstatus ?></option>
<?php
}
?>
</select>
</div>
As I mentioned, after looking at this code I know there has to be a better way to do this I just don't know how. Any help would be greatly appreciated.