Hello, I have a problem with my list down menu. My list down menu will display data from MySQL. It working very well. But, there are problems when I add if else statement. I want to display the list down menu based on the one field from MySQL. For example :
I named the field as 'saluran'. This field has two value which are 'D' and 'L'.
Based on this field, the list down menu will display. If 'saluran' is D, then the list down menu will display from 'status' table. If 'saluran' is L, then the list down menu will display data from 'user' table.
I tried change the code many times, but still there are problems when I add if else statement. Please help me asap. Thank you in advanced.
Here my code without if else statement:
<select name="from" id="from" >
<option value="" selected>-From-</option>
<?php
$resultSubject = mysql_query("SELECT * FROM status");
while($row = mysql_fetch_array( $resultSubject))
{
$ID = $row['ID'];
$codeStatus = $row['codeStatus'];
$statusSurat = $row['statusSurat'];
?>
<option value="<?php echo $codeStatus;?>"><?php echo $statusSurat;?></option>
<?php } ?>
</select>
</select>
<select name="to" id="to" >
<option value="" selected>-To-</option>
<?php
$resultSubject = mysql_query("SELECT * FROM status");
while($row = mysql_fetch_array( $resultSubject))
{
$ID = $row['ID'];
$codeStatus = $row['codeStatus'];
$statusSurat = $row['statusSurat'];
?>
<option value="<?php echo $codeStatus;?>"><?php echo $statusSurat;?></option>
<?php } ?>
</select>
</select>
Here my code with if else statement :
<?php
if ( $saluran == 'D')
{
echo "<select name='from_D' id='from_D' >
<option value='' selected>-From-</option>
<?php
$resultSubject = mysql_query('SELECT * FROM status');
while($row = mysql_fetch_array( $resultSubject))
{
$ID = $row['ID'];
$codeStatus = $row['codeStatus'];
$statusSurat = $row['statusSurat'];
?>
<option value='<?php echo $codeStatus;?>'><?php echo $statusSurat;?></option>
<?php } ?>
</select>
</select>
<select name='to_D' id='to_D' >
<option value='' selected>-To-</option>
<?php
$resultSubject = mysql_query('SELECT * FROM status');
while($row = mysql_fetch_array( $resultSubject))
{
$ID = $row['ID'];
$codeStatus = $row['codeStatus'];
$statusSurat = $row['statusSurat'];
?>
<option value='<?php echo $codeStatus;?>'><?php echo $statusSurat;?></option>
<?php } ?>
</select>
</select>";
}
else
{
echo "<select name='from_L' id='from_L' >
<option value='' selected>-From-</option>
<?php
$resultSubject = mysql_query('SELECT * FROM user');
while($row = mysql_fetch_array( $resultSubject))
{
$ID = $row['ID'];
$name = $row['name'];
?>
<option value='<?php echo $ID;?>'><?php echo $name;?></option>
<?php } ?>
</select>
</select>
<select name='to_L' id='to_L' >
<option value='' selected>-To-</option>
<?php
$resultSubject = mysql_query('SELECT * FROM user');
while($row = mysql_fetch_array( $resultSubject))
{
$ID = $row['ID'];
$name = $row['name'];
?>
<option value='<?php echo $codeStatus;?>'><?php echo $name;?></option>
<?php } ?>
</select>
</select>";
}
?>