Jump to content

help with fetching rows.


gammaman

Recommended Posts

I have code that is fetching the wrong rows (in a sense) See I have this table that is supposed to output two different types of rows, depeding on weather or not a student is or is not registerd in a Course.

These are the courses the student is already taking.  And this is correct according to my database and is also correct as this is what the query fetches.

MTH200
ENG130
PHY300

However, my table says it is these courses, which are as you would have guessed, the first three rows of the table.

CourseID CourseName                Seats              Register 
BCS120 C++ Beginner 25                                Already Took Course 
ENG13        Literature 30           Already Took Course 
MTH200 Calculus 3 20                        Already Took Course 
3 IND400 Operations 25                                   Register 
3 PHY300 Nuclear Phys 20                                Register 
3 BCS345 Intro to Jav 25 Register 
3 SOC101 Intro to Soc 30 Register 

You get the idea.  Here is the code.
[code = php]
<?php
$conn=mysql_connect("localhost","fierm","13183");

  if(!$conn){
    echo "failed";
}else{ 
   mysql_select_db("fierm");

session_start();
$_SESSION['student']['user'];
$_SESSION['student']['pass'];
echo "{$_SESSION['student']['user']}";
echo "Choose a Course to Register";
   
     $result=mysql_query("select CourseID,CourseName,SeatLimit from Course");
     $result1=mysql_query("Select CourseID,StudentID from Rcourse where StudentID='{$_SESSION['student']['user']}'"); 
     echo "<table border = \"1\">";
     echo "<tr><td>CourseID</td><td>CourseName</td><td>Seats</td><td>Register</tr>";
     
     while($row=mysql_fetch_array($result))
     {
       $CourseID = $row['CourseID'];
       $CourseName= $row['CourseName'];
       $SeatLimit= $row['SeatLimit'];
       $r=mysql_fetch_array($result1);
       $Course = $r['CourseID'];
       //print_r($Course);
       echo "$Course";
       //$cou=mysql_num_rows($result1);
       //echo "$cou";
       if($r>0){
        foreach($r as $value){
              
             $value = "Already Took Course";
          }
       }
       
       else{
            $value="<a href=\"checkRegCourses.php?ci=$row[0]&cn=$row[1]\">Register</a>";
       } 
     //$strUrl = "<a href=\"checkRegCourses.php?ci=$row[0]&cn=$row[1]\">Register</a>";
     echo "<tr><td>$CourseID</td><td>$CourseName</td><td>$SeatLimit</td><td>$value</td></tr>\n";
     }
     echo "</table>";
}
?>

 

 

 

 

 

 

 

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/103632-help-with-fetching-rows/
Share on other sites

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.