gammaman Posted April 22, 2008 Share Posted April 22, 2008 What is wrong with this code, when I execute it I get a blank page. $conn=mysql_connect("localhost","fierm","13183"); if (!$conn){ echo "failed"; }else{ mysql_select_db("fierm"); session_start(); echo "here"; $_SESSION['student']['user']; $_SESSION['student']['pass']; echo '<table border = "1">'; $result=mysql_query("select CourseID,CourseName,StudentID,Grade FROM Rcourse WHERE StudentID='{$_SESSION['student']['user']}'"); $cou=mysql_num_rows($result); if ($cou==0){ echo "Not in Any Courses"; } else{ echo "<tr><th>CourseID</th><th>CourseName</th><th>Grade<th>Drop Course</th></tr>"; while ($row=mysql_fetch_array($result)) { $CourseID = $row['CourseID']; $grade = $row['Grade']; $result1=mysql_query("SELECT * FROM Course WHERE CourseID='$CourseName'"); $r=mysql_fetch_array($result1); $course=$r['CourseName']; if (ltrim ($grade) = ""){ $value "---"; } else{ $value='<a href = \"checkStuDrop?cid='.$CourseID.'">Drop</a>'; } echo "<tr><td>$CourseName</td><td>$course</td><td>$value</td></tr>"; } } echo "</table>"; Quote Link to comment Share on other sites More sharing options...
craygo Posted April 22, 2008 Share Posted April 22, 2008 try this <?php mysql_select_db("fierm"); session_start(); echo "here"; $_SESSION['student']['user']; $_SESSION['student']['pass']; echo '<table border = "1">'; $result=mysql_query("select CourseID,CourseName,StudentID,Grade FROM Rcourse WHERE StudentID='{$_SESSION['student']['user']}'"); $cou=mysql_num_rows($result); if ($cou==0){ echo "Not in Any Courses"; } else{ echo "<tr><th>CourseID</th><th>CourseName</th><th>Grade<th>Drop Course</th></tr>"; while ($row=mysql_fetch_array($result)) { $CourseID = $row['CourseID']; $grade = $row['Grade']; $result1=mysql_query("SELECT * FROM Course WHERE CourseID='$CourseName'"); $r=mysql_fetch_array($result1); $course=$r['CourseName']; if (ltrim ($grade) == ""){ // 2 equals signs here $value = "---"; // forgot your equal sign here } else{ $value='<a href = \"checkStuDrop?cid='.$CourseID.'">Drop</a>'; } echo "<tr><td>$CourseName</td><td>$course</td><td>$value</td></tr>"; } } echo "</table>"; ?> Ray Quote Link to comment Share on other sites More sharing options...
jonsjava Posted April 22, 2008 Share Posted April 22, 2008 <?php $conn=mysql_connect("localhost","fierm","13183"); if (!$conn){ echo "failed"; }else{ mysql_select_db("fierm"); session_start(); echo "here"; $_SESSION['student']['user']; $_SESSION['student']['pass']; echo '<table border = "1">'; $result=mysql_query("select CourseID,CourseName,StudentID,Grade FROM Rcourse WHERE StudentID='{$_SESSION['student']['user']}'"); $cou=mysql_num_rows($result); if ($cou==0){ echo "Not in Any Courses"; } else{ echo "<tr><th>CourseID</th><th>CourseName</th><th>Grade<th>Drop Course</th></tr>"; while ($row=mysql_fetch_array($result)) { $CourseID = $row['CourseID']; $grade = $row['Grade']; $CourseName = $row['CourseName']; //verify that this is accurate $result1=mysql_query("SELECT * FROM Course WHERE CourseID='$CourseName'"); $r=mysql_fetch_array($result1); $course=$r['CourseName']; if (ltrim($grade) == ""){ $value = "---"; } else{ $value='<a href = \"checkStuDrop?cid='.$CourseID.'">Drop</a>'; } echo "<tr><td>$CourseName</td><td>$course</td><td>$value</td></tr>"; } } echo "</table>"; } I posted it anways Quote Link to comment Share on other sites More sharing options...
gammaman Posted April 22, 2008 Author Share Posted April 22, 2008 Now the page displays but I do not get the desired output. I will work on it and let you guys know. Thanks for the help. Quote Link to comment Share on other sites More sharing options...
craygo Posted April 22, 2008 Share Posted April 22, 2008 As java said I think it should be $course=$row['CourseName']; ray Quote Link to comment Share on other sites More sharing options...
gammaman Posted April 22, 2008 Author Share Posted April 22, 2008 The table header is displayed but no rows are being fetched. Quote Link to comment Share on other sites More sharing options...
jonsjava Posted April 22, 2008 Share Posted April 22, 2008 add or die(mysql_error()); at the end of your current mysql_query()'s (removing the other ";") Quote Link to comment Share on other sites More sharing options...
gammaman Posted April 22, 2008 Author Share Posted April 22, 2008 I dont't know about that because I have another fetch which is assigned to $r. Quote Link to comment Share on other sites More sharing options...
jonsjava Posted April 22, 2008 Share Posted April 22, 2008 this is for debugging only. Quote Link to comment Share on other sites More sharing options...
craygo Posted April 22, 2008 Share Posted April 22, 2008 Shouldn't this $result1=mysql_query("SELECT * FROM Course WHERE CourseID='$CourseName'"); be this $result1=mysql_query("SELECT * FROM Course WHERE CourseID='$CourseID'") or die(mysql_error()); Add some error checking! Ray Quote Link to comment Share on other sites More sharing options...
gammaman Posted April 22, 2008 Author Share Posted April 22, 2008 I fixed that now but it still does not fetch any rows. Quote Link to comment Share on other sites More sharing options...
jonsjava Posted April 22, 2008 Share Posted April 22, 2008 no errors + no rows: usually = no data in db. hm.... can I get a copy of the table schema (just the schema, not the data) Quote Link to comment Share on other sites More sharing options...
gammaman Posted April 22, 2008 Author Share Posted April 22, 2008 It works now, I had a couple of vars spelled incorrectly. Thanks for the help. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.