Re: Warning: mysql_fetch_array() expects parameter 1 to be resource
Posted by:
Abdo Boriz
Date: November 29, 2010 03:11PM
Barry,
"Have you tried running the query from the mysql command line client to see if it returns the expected result?"
I use PHPmyadmin and I clicked on where it says SQL and ran the query. I found exactly what's wrong. there was a typo in two of the fields. So I was able to fix that problem and display the query successfully. Also both echo "$instudID"; and echo $_POST['inputstudID']; returned the number I entered.
The only problem is php is outputing blank except the header part although the SQL showing the data correctly. Please look at my code one more time and see why php is not outputing the desiered data. Thank you again.
Abdo
-------
<?php
include'dbConnectionFile2.php';
$instudID=$_POST['inputstudID'];
if (!$_POST['submit']) {
echo "Please enter your student ID and click on Submit Query button to find out your schedule.";
}
else {
$query="SELECT e.studID, e.courseNum, e.facID, e.sessionID, e.classroomID
,s.studID
,s.fname
,s.lname
,c.courseNum
,c.days
,c.time
,c.description
,c.credits
,f.facID
,f.ffname
,f.flname
,t.sessionID
,t.session
,l.classroomID
,l.building
FROM student s
JOIN enrollment e
ON e.studID = s.studID
JOIN course c
ON c.courseNum = e.courseNum
JOIN faculty f
ON f.facID = e.facID
JOIN term t
ON t.sessionID = e.sessionID
JOIN location l
ON l.classroomID = e.classroomID
WHERE s.studID='.$instudID.'";
$result=mysql_query($query);
echo "<h2> Schedule Details </h2>";
echo " <table border='1' cellpadding '10'>";
echo "<tr><th>Student ID</th>";
echo "<th>Student First Name</th>";
echo "<th>Student Last Name </th>";
echo "<th>Course Number</th>";
echo "<th>Description</th>";
echo "<th>Days</th>";
echo "<th>Time</th>";
echo "<th>Credits</th>";
echo "<th><th>Faculty ID</th>";
echo "<th>Faculty First Name</th>";
echo "<th>Faculty Last Name </th>";
echo "<th>Session ID</th>";
echo "<th>Session</th>";
echo "<th>Location ID</th>";
echo "<th>Building</th>";
echo "<th></th><th></th></tr>";
while($studentinfo=mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $studentinfo['studID'] . "</td>";
echo "<td>" . $studentinfo['fname'] . "</td>";
echo "<td>" . $studentinfo['lname'] . "</td>";
echo "<td>" . $studentinfo['courseNum'] . "</td>";
echo "<td>" . $studentinfo['decription'] . "</td>";
echo "<td>" . $studentinfo['days'] . "</td>";
echo "<td>" . $studentinfo['time'] . "</td>";
echo "<td>" . $studentinfo['credits'] . "</td>";
echo "<td>" . $studentinfo['facID'] . "</td>";
echo "<td>" . $studentinfo['ffname'] . "</td>";
echo "<td>" . $studentinfo['flname'] . "</td>";
echo "<td>" . $studentinfo['sessionID'] . "</td>";
echo "<td>" . $studentinfo['session'] . "</td>";
echo "<td>" . $studentinfo['classroomID'] . "</td>";
echo "<td>" . $studentinfo['Building'] . "</td>";
echo "<td>" . "<a href=\"editstudentenrollment.php?id=". $studentinfo['studID']."\">Edit</a>" . "</td>";
echo "<td>" . "<a href=\"dropclass.php?id=". $studentinfo['studID']."\">Delete</a>" . "</td>";
echo "</tr>";
}
echo "</table>";
}
?>