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

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Thanks, i got to that code.  But I am still getting the error message:"Parse error: parse error, unexpected $ in ... on line 233."  Line 233 is after the last line of the code.  I think this means I probably have an undefined variable somewhere.

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.