Jump to content

[SOLVED] If/Else Statment within an Select/Option Group


karatekid36

Recommended Posts

Howdy Everyone,

    I have the following code where I want to create an update query in a form so that I can update my groups attendance.  The variables 100% are working and are pulling the correct info.  In the update attendance column, I would like an If else statement that says if the attend_status == present echo  SELECTED VALUE="", so that the pull down menu will display the current attendance value.  From there I will select the new update attendance info and then submit it using an update query.  Below is the code.  I am running into other problems with the quotation marks in such because this is all located within the <php> tags.  Thanks for the help and let me know if I am being unclear at all.  THANKS!

 

 

<code>// Table header.

echo '<h1 align="center">' . $row2['name'] .', ' . $row2['date'] .'</h1> <table align="center" cellspacing="0" cellpadding="5">

<tr>

<td align="left"><b>Name</b></td>

<td align="left"><b>Current Attendance</b></td>

    <td align="left"><b>Update Attendance</b></td>

</tr>

';

 

// Fetch and print all the records.

$bg = '#eeeeee'; // Set the background color.

while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {

$bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee'); // Switch the background color.

echo '<tr bgcolor="' . $bg . '">

<td align="left">' . $row['BrotherName'] . '</td>

<td align="left">' . $row['attend_status'] . '</td>

 

<td><select><option>Present</option><option>Excused</option><option>Unexcused</option></select></td>

</tr>

';

}</code>

Link to comment
Share on other sites


<?php
// Table header.
echo '<h1 align="center">' . $row2['name'] .', ' . $row2['date'] .'</h1> <table align="center" cellspacing="0" cellpadding="5">
<tr>
   <td align="left">Name</td>
   <td align="left">Current Attendance</td>
    <td align="left">Update Attendance</td>
</tr>
';

// Fetch and print all the records.
$bg = '#eeeeee'; // Set the background color.
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
   $bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee'); // Switch the background color.
   echo '<tr bgcolor="' . $bg . '">
      <td align="left">' . $row['BrotherName'] . '</td>
      <td align="left">' . $row['attend_status'] . '</td>
      
      <td><select><option>Present</option><option>Excused</option><option>Unexcused</option></select></td>
   </tr>
   ';
}?>

 

 

what is the exact problem you get? please be more informative?

Link to comment
Share on other sites

try

echo '<tr bgcolor="' . $bg . '">
      <td align="left">' . $row['BrotherName'] . '</td>
      <td align="left">' . $row['attend_status'] . '</td>
      
      <td><select name="updated">
      	<option', $x = $row['attend_status'] == 'Present' ? ' selected="selected"' : '' ,'>Present</option>
      	<option', $x = $row['attend_status'] == 'Excused' ? ' selected="selected"' : '' ,'>Excused</option>
      	<option', $x = $row['attend_status'] == 'Unexcused' ? ' selected="selected"' : '' ,'>Unexcused</option>
      </select></td>
   </tr>
   ';

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.