techker Posted December 5, 2011 Share Posted December 5, 2011 hey guys i keep on getting this error when i have no results..i need a full no results.. Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/techker/public_html/Site/New/Main/Rapport.php on line 46 No results found. Please check often to see if we have more data.. $Etudiant=$_GET['E_ID']; $query = "SELECT * FROM `Etudiant` WHERE `Code_P` ='$Etudiant'"; $numresults=mysql_query($query); $row10 = mysql_fetch_assoc($numresults); if ($row10 == 0) { echo "<h4>Results</h4>"; echo "<p>Sorry, your search: returned zero results</p>"; } $Nom = $row10["Nom"]; $Prenom = $row10["Prenom"]; $fileSQL="SELECT `N_Etudiant` FROM `Expulsion` WHERE `Nom` LIKE '$Nom' AND `Prenom` LIKE '$Prenom' LIMIT 0 , 30"; $fileLIST=mysql_query($fileSQL); if(mysql_num_rows($fileLIST) > 0){ while ($row = mysql_fetch_array($fileLIST)) { Quote Link to comment Share on other sites More sharing options...
gizmola Posted December 5, 2011 Share Posted December 5, 2011 Your code does not check to see if the queries are valid, it simply assumes that they are. Clearly in certain cases the queries are not valid, and you have errors. There is a link in my signature that describes how to approach this properly. Quote Link to comment Share on other sites More sharing options...
techker Posted December 5, 2011 Author Share Posted December 5, 2011 well what mess is me up is that i have 1 query that depends on the other.. the first $Etudiant=$_GET['E_ID']; $query = "SELECT * FROM `Etudiant` WHERE `Code_P` ='$Etudiant'"; $numresults=mysql_query($query); $row10 = mysql_fetch_assoc($numresults); get the id and the second gets the search results in another table $Nom = $row10["Nom"]; $Prenom = $row10["Prenom"]; $fileSQL="SELECT `N_Etudiant` FROM `Expulsion` WHERE `Nom` LIKE '$Nom' AND `Prenom` LIKE '$Prenom' LIMIT 0 , 30"; $fileLIST=mysql_query($fileSQL); Quote Link to comment Share on other sites More sharing options...
gizmola Posted December 6, 2011 Share Posted December 6, 2011 Again -- read the link in my signature named: "My PHP script with MySQL doesn't work?" and implement the recommendations there. Quote Link to comment Share on other sites More sharing options...
fenway Posted December 6, 2011 Share Posted December 6, 2011 Also, mysql injection vulnerabilities galore. Quote Link to comment Share on other sites More sharing options...
techker Posted December 6, 2011 Author Share Posted December 6, 2011 ya i seen your page.. but the thing is is that the first query is for the second to work.. inless i can do an inner join ? cause i can't put the second query but on the first i can't.. if (!$result) { echo "Could not successfully run query ($sql) from DB: " . mysql_error(); exit; } while ($row = mysql_fetch_array()) { .... } Quote Link to comment Share on other sites More sharing options...
fenway Posted December 7, 2011 Share Posted December 7, 2011 Say what? Quote Link to comment Share on other sites More sharing options...
gizmola Posted December 7, 2011 Share Posted December 7, 2011 techker: the point is that if the first query fails OR it does not return a row, there is no reason to do the 2nd query because it will also fail. This is why you need to check the result of the query, and only do that if you have a result AND you were able to get a row to drive the 2nd query. This is simple IF THEN ELSE logic. I could write the code for you, but the purpose of this forum is to help people do for themselves. If you have new code that shows your progress but still doesn't work, we will help out, but so far I've not seen any new code from you that reflects you understand the advice I provided. Quote Link to comment Share on other sites More sharing options...
techker Posted December 7, 2011 Author Share Posted December 7, 2011 ok thx! 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.