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>"; Link to comment https://forums.phpfreaks.com/topic/102336-help-error-in-code/ 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 Link to comment https://forums.phpfreaks.com/topic/102336-help-error-in-code/#findComment-523992 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 Link to comment https://forums.phpfreaks.com/topic/102336-help-error-in-code/#findComment-523993 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. Link to comment https://forums.phpfreaks.com/topic/102336-help-error-in-code/#findComment-523999 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 Link to comment https://forums.phpfreaks.com/topic/102336-help-error-in-code/#findComment-524001 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. Link to comment https://forums.phpfreaks.com/topic/102336-help-error-in-code/#findComment-524002 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 ";") Link to comment https://forums.phpfreaks.com/topic/102336-help-error-in-code/#findComment-524004 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. Link to comment https://forums.phpfreaks.com/topic/102336-help-error-in-code/#findComment-524008 Share on other sites More sharing options...
jonsjava Posted April 22, 2008 Share Posted April 22, 2008 this is for debugging only. Link to comment https://forums.phpfreaks.com/topic/102336-help-error-in-code/#findComment-524010 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 Link to comment https://forums.phpfreaks.com/topic/102336-help-error-in-code/#findComment-524012 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. Link to comment https://forums.phpfreaks.com/topic/102336-help-error-in-code/#findComment-524018 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) Link to comment https://forums.phpfreaks.com/topic/102336-help-error-in-code/#findComment-524020 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. Link to comment https://forums.phpfreaks.com/topic/102336-help-error-in-code/#findComment-524061 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.