Jump to content

help echo different rows based on (if not null)


gammaman

Recommended Posts

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

   


}
?>

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

 

 

 

 

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.

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.