ifis Posted January 5, 2008 Share Posted January 5, 2008 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 https://forums.phpfreaks.com/topic/84645-solved-adding-if-statement-to-while-statement/ Share on other sites More sharing options...
papaface Posted January 5, 2008 Share Posted January 5, 2008 You have no {} on your if/else statement. Link to comment https://forums.phpfreaks.com/topic/84645-solved-adding-if-statement-to-while-statement/#findComment-431362 Share on other sites More sharing options...
ifis Posted January 5, 2008 Author Share Posted January 5, 2008 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 https://forums.phpfreaks.com/topic/84645-solved-adding-if-statement-to-while-statement/#findComment-431369 Share on other sites More sharing options...
revraz Posted January 5, 2008 Share Posted January 5, 2008 Remove all those periods. Link to comment https://forums.phpfreaks.com/topic/84645-solved-adding-if-statement-to-while-statement/#findComment-431372 Share on other sites More sharing options...
papaface Posted January 5, 2008 Share Posted January 5, 2008 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 https://forums.phpfreaks.com/topic/84645-solved-adding-if-statement-to-while-statement/#findComment-431395 Share on other sites More sharing options...
ifis Posted January 5, 2008 Author Share Posted January 5, 2008 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 https://forums.phpfreaks.com/topic/84645-solved-adding-if-statement-to-while-statement/#findComment-431406 Share on other sites More sharing options...
revraz Posted January 5, 2008 Share Posted January 5, 2008 Means you have a open bracket some where } ] ) Link to comment https://forums.phpfreaks.com/topic/84645-solved-adding-if-statement-to-while-statement/#findComment-431410 Share on other sites More sharing options...
ifis Posted January 5, 2008 Author Share Posted January 5, 2008 Just found that missed }. Thanks for the help! Link to comment https://forums.phpfreaks.com/topic/84645-solved-adding-if-statement-to-while-statement/#findComment-431411 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.