Jump to content

[SOLVED] Adding If statement to while statement


ifis

Recommended Posts

I have an array that dispalys information a specific user has inputed into the table.  I want the users to be able to update the passed field if it is blank.  So I want to add an if statement that says if Passed == 'null' {echo "form..."} else echo ". $row['Passed?'] . "

How would I do it?  Here is the code I currently have.

$sql = "SELECT * FROM Endorsementlog WHERE Username= '{$_SESSION['myusername']}'";
$result=mysql_query($sql);

echo "<h3>Endorsement Log:</h3>";
echo "<table border='0'>
<tr>
<th>Date</th>
<th>Student</th>
<th>Endorsement</th>
<th>Passed</th>
</tr>";

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['Date'] . "</td>";
  echo "<td>" . $row['Student'] . "</td>";
  echo "<td>" . $row['Endorsement'] . "</td>";
  if ( $row['Passed?'] .== 'null')
echo"<form id='elog' name='form2' method='post' action=''>
  <select name='Passed?' id='Passed?'>
    <option>Yes</option>
    <option>No</option>
  </select>
</form>";
else
  echo "<td>" . $row['Passed?'] . "</td>";
  echo "</tr>";
  }
echo "</table>";
?>

Any suggestions?  Thanks

I added the {, but am getting the message:"Parse error: parse error, unexpected '.' "

if I take out the '.', will it still sequence to the next row?  Here is the current code.

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['Date'] . "</td>";
  echo "<td>" . $row['Student'] . "</td>";
  echo "<td>" . $row['Endorsement'] . "</td>";
  if (. $row['Passed?']== 'null')
  {
echo"<form id='elog' name='form2' method='post' action=''>
  <select name='Passed?' id='Passed?'>
    <option>Yes</option>
    <option>No</option>
  </select>
</form>";
}
else
{
  echo "<td>" . $row['Passed?'] . "</td>";
  	}
  echo "</tr>";
echo "</table>";

 

Should be:

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['Date'] . "</td>";
  echo "<td>" . $row['Student'] . "</td>";
  echo "<td>" . $row['Endorsement'] . "</td>";
  if ($row['Passed?']== 'null')
  {
echo"<form id='elog' name='form2' method='post' action=''>
  <select name='Passed?' id='Passed?'>
    <option>Yes</option>
    <option>No</option>
  </select>
</form>";
}
else
{
  echo "<td>" . $row['Passed?'] . "</td>";
  	}
  echo "</tr>";
echo "</table>";

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.