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>


<?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?

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>
   ';

Right now I am receiving this error from your code which I am trying to debug...

 

 

Parse error: syntax error, unexpected $end in /home/carrigan/public_html/php_attend/event_attendance_admin.php on line 113

 

 

Let me know what you think.

 

 

 

 

 

 

 

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.