gammaman Posted April 24, 2008 Share Posted April 24, 2008 I have several problems. First off I have a syntax error because the page loads blank. Secondly I know the code won't work because mine never does. So please help me. I am trying to echo two different rows depedning on weather or not a certain field for that corresponding row is NULL (blank) or not. If it is blank I want a textbox to appear where that spot is so that a value can be passed to another page and I can update the row. If it is not NULL (blank) I want the row echoed normally with all of the values. <?php $conn=mysql_connect("localhost","fierm","13183"); if(!$conn){ echo "failed"; }else{ mysql_select_db(fierm); $StudentID = $_POST['id']; session_start(); $_SESSION['admin']['admins']; $_SESSION['admin']['adminpass']; $result=mysql_query("select CourseID,CourseName,Grade From Rcourse WHERE StudentID='$StudentID'"); $cou=mysql_num_rows($result); if ($cou==0){ echo "Not in Any Courses"; }else{ echo '<table border="1">'; echo "<tr><th>CourseID</th><th>CourseName</th><th>Grade</th></tr>"; while ($row=mysql_fetch_array($result)) { $CourseID= $row['CourseID']; $grade = $row['Grade']; $Course=$row['CourseName']; if (($grade) ! = "NULL"){ $value='<form action="updateGrades.php" method= "post">'; echo "<br />"; '<input name = "grd" type="text" />'; }else{ $value = "$grade"; } #end if...else echo "<tr><td>$CourseID</td><td>$course</td><td>$value</td></tr>"; } #end while } #if...else echo "</form>"; echo "</table>"; echo "<b>Return to Student Page</b>"; echo "<a href = \"student.php\">Return to Student Page</a>"; } ?> Link to comment https://forums.phpfreaks.com/topic/102803-help-echo-different-rows-based-on-if-not-null/ Share on other sites More sharing options...
dptr1988 Posted April 24, 2008 Share Posted April 24, 2008 If a variable is 'NULL' in PHP it's almost like it doesn't exist. What you need to do is check for an empty string like this: <?php if ($grade != "") { $value='<form action="updateGrades.php" method= "post">'; echo "<br />" . '<input name = "grd" type="text" />'; }else{ $value = $grade } ?> Link to comment https://forums.phpfreaks.com/topic/102803-help-echo-different-rows-based-on-if-not-null/#findComment-526574 Share on other sites More sharing options...
DarkWater Posted April 24, 2008 Share Posted April 24, 2008 if (!is_null($grade)) { } else { } Do it like that if you want. Link to comment https://forums.phpfreaks.com/topic/102803-help-echo-different-rows-based-on-if-not-null/#findComment-526579 Share on other sites More sharing options...
gammaman Posted April 24, 2008 Author Share Posted April 24, 2008 It works somewhat now. This is what the table looks like. (Sorry don't know how to display it as an image. CourseID CourseName Grade MTH200 Calculus 3 ENG130 Literature B+ See on the MTH row grade is blank. I want a textbox there and also for each subsequent row that has a blank value. I tried to code it, you can see it in my post above. Just need help with tweaking it to do this task. Link to comment https://forums.phpfreaks.com/topic/102803-help-echo-different-rows-based-on-if-not-null/#findComment-526601 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.