abch624 Posted August 27, 2008 Share Posted August 27, 2008 Hi All, I have this code echo $sql = "SELECT DISTINCT E.name, E.dateOfBirth, E.amisID, E.jamaat, F.institute, G.completedUniversity, G.currentUniversity, D.A* AS aStarGcse, D.A AS aGcse, D.B AS bGcse, D.C AS cGcse, D.D AS dGcse, D.E AS eGcse, D.F AS fGcse, D.G AS gGcse, A.A* AS aStarALevel, A.A AS aALevel, A.B AS bALevel, A.C AS cALevel, A.D AS dALevel, A.E AS eALevel, A.F AS fALevel, B.employed, B.quidanceRequired, C.subjects FROM $tbl_personaldetails E JOIN $tbl_study F ON (E.studyID = F.studyID) JOIN $tbl_university G ON (G.universityID = F.universityID) JOIN $tbl_gcseresult D ON (D.gcseID = F.gcseID) JOIN $tbl_currentsubjects C ON (C.currentSubjectsID = F.currentSubjectsID) JOIN $tbl_careerguidance B ON (B.careerGuidanceID = F.careerGuidanceID) JOIN $tbl_alevelresult A ON (A.aLevelID = A.aLevelID) WHERE E.name LIKE '%$name%' ORDER BY E.name"; if (mysql_query($sql)) { echo "yes"; } else { mysql_error(); } This sql statement generates this error : SELECT DISTINCT E.name, E.dateOfBirth, E.amisID, E.jamaat, F.institute, G.completedUniversity, G.currentUniversity, D.A* AS aStarGcse, D.A AS aGcse, D.B AS bGcse, D.C AS cGcse, D.D AS dGcse, D.E AS eGcse, D.F AS fGcse, D.G AS gGcse, A.A* AS aStarALevel, A.A AS aALevel, A.B AS bALevel, A.C AS cALevel, A.D AS dALevel, A.E AS eALevel, A.F AS fALevel, B.employed, B.quidanceRequired, C.subjects FROM personaldetails E JOIN study F ON (E.studyID = F.studyID) JOIN university G ON (G.universityID = F.universityID) JOIN gcseresult D ON (D.gcseID = F.gcseID) JOIN currentsubjects C ON (C.currentSubjectsID = F.currentSubjectsID) JOIN careerguidance B ON (B.careerGuidanceID = F.careerGuidanceID) JOIN alevelresult A ON (A.aLevelID = A.aLevelID) WHERE E.name LIKE '%Zahid%' ORDER BY E.name Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\wamp\www\Talim\searchdo.php on line 53 Please advise on why i get this error. Thanks - Zahid Link to comment https://forums.phpfreaks.com/topic/121561-solved-sql-error/ Share on other sites More sharing options...
Mchl Posted August 27, 2008 Share Posted August 27, 2008 Try this: if ($result = mysql_query($sql)) { echo "yes"; } else { mysql_error(); } echo mysql_num_rows($result); Link to comment https://forums.phpfreaks.com/topic/121561-solved-sql-error/#findComment-626948 Share on other sites More sharing options...
revraz Posted August 27, 2008 Share Posted August 27, 2008 Where is your mysql_num_rows line? Also, remove the echo from in front of $sql, I am not sure if you can do that. Link to comment https://forums.phpfreaks.com/topic/121561-solved-sql-error/#findComment-626950 Share on other sites More sharing options...
abch624 Posted August 27, 2008 Author Share Posted August 27, 2008 echo $sql = "SELECT DISTINCT E.name, E.dateOfBirth, E.amisID, E.jamaat, F.institute, G.completedUniversity, G.currentUniversity, D.A* AS aStarGcse, D.A AS aGcse, D.B AS bGcse, D.C AS cGcse, D.D AS dGcse, D.E AS eGcse, D.F AS fGcse, D.G AS gGcse, A.A* AS aStarALevel, A.A AS aALevel, A.B AS bALevel, A.C AS cALevel, A.D AS dALevel, A.E AS eALevel, A.F AS fALevel, B.employed, B.quidanceRequired, C.subjects FROM $tbl_personaldetails E JOIN $tbl_study F ON (E.studyID = F.studyID) JOIN $tbl_university G ON (G.universityID = F.universityID) JOIN $tbl_gcseresult D ON (D.gcseID = F.gcseID) JOIN $tbl_currentsubjects C ON (C.currentSubjectsID = F.currentSubjectsID) JOIN $tbl_careerguidance B ON (B.careerGuidanceID = F.careerGuidanceID) JOIN $tbl_alevelresult A ON (A.aLevelID = A.aLevelID) WHERE E.name LIKE '%$name%' ORDER BY E.name"; if (mysql_query($sql)) { echo "yes"; } else { mysql_error(); } if (mysql_num_rows($result) > 0) { while ($row=mysql_fetch_array($result)) { $num = $num + 1; echo $row['name']; } } Link to comment https://forums.phpfreaks.com/topic/121561-solved-sql-error/#findComment-626954 Share on other sites More sharing options...
Mchl Posted August 27, 2008 Share Posted August 27, 2008 You use $result in mysql_num_rows(), but where do you set it? Nowhere. Change if (mysql_query($sql)) { to if ($result = mysql_query($sql)) { Link to comment https://forums.phpfreaks.com/topic/121561-solved-sql-error/#findComment-626957 Share on other sites More sharing options...
abch624 Posted August 27, 2008 Author Share Posted August 27, 2008 Solved it guys Link to comment https://forums.phpfreaks.com/topic/121561-solved-sql-error/#findComment-626970 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.