spearchilduser Posted March 26, 2012 Share Posted March 26, 2012 can anyone see a error with this code ? $query = mysql_query("SELECT * FROM project WHERE Module_Code ='$schemelevel' AND Available ='Yes'"); $result = mysql_query($query); while ($myrow = mysql_fetch_row($result)) { seems to be a issue using fetch_row ($result) telling me theres a issue with the resource Quote Link to comment https://forums.phpfreaks.com/topic/259742-help/ Share on other sites More sharing options...
AyKay47 Posted March 26, 2012 Share Posted March 26, 2012 mysql_query expects it's first argument to be a string containing valid SQL, which is what you have contained in $query. With $result, you are attempting to query a query resource, which is invalid, the code should read: $query = "SELECT * FROM project WHERE Module_Code = '$schemelevel' AND Available = 'Yes'"; $result = mysql_query($query); while ($myrow = mysql_fetch_row($result)) { //code } Quote Link to comment https://forums.phpfreaks.com/topic/259742-help/#findComment-1331217 Share on other sites More sharing options...
spearchilduser Posted March 26, 2012 Author Share Posted March 26, 2012 Hi thanx for the reply yer that makes scence However now when i run the page it dispalys nothing when everythign is worded correclt in the correct format :s Quote Link to comment https://forums.phpfreaks.com/topic/259742-help/#findComment-1331219 Share on other sites More sharing options...
AyKay47 Posted March 26, 2012 Share Posted March 26, 2012 Is there any other code in the page? Try this debugging code and post the results: $sql = "SELECT * FROM project WHERE Module_Code = '$schemelevel' AND Available = 'Yes'"; $result = mysql_query($sql) or die($sql .'<br />'. mysql_error()); if(mysql_num_rows($result) == 0) { echo "no results"; exit; } while ($myrow = mysql_fetch_row($result)) { //code } Quote Link to comment https://forums.phpfreaks.com/topic/259742-help/#findComment-1331221 Share on other sites More sharing options...
spearchilduser Posted March 26, 2012 Author Share Posted March 26, 2012 just printing no results but i know there is data in the table that should display results and the fields are named correclty as well Quote Link to comment https://forums.phpfreaks.com/topic/259742-help/#findComment-1331223 Share on other sites More sharing options...
AyKay47 Posted March 26, 2012 Share Posted March 26, 2012 alright, then try this: $sql = "SELECT * FROM project WHERE Module_Code = '$schemelevel' AND Available = 'Yes'"; $result = mysql_query($sql) or die($sql .'<br />'. mysql_error()); if(mysql_num_rows($result) == 0) { echo "no results <br/ >"; echo $sql; exit; } while ($myrow = mysql_fetch_row($result)) { //code } Quote Link to comment https://forums.phpfreaks.com/topic/259742-help/#findComment-1331225 Share on other sites More sharing options...
spearchilduser Posted March 26, 2012 Author Share Posted March 26, 2012 hey same thing except its now displayign the query no results SELECT * FROM project WHERE Module_Code = 'Bsc Hons' AND Available = 'Yes' Quote Link to comment https://forums.phpfreaks.com/topic/259742-help/#findComment-1331235 Share on other sites More sharing options...
AyKay47 Posted March 26, 2012 Share Posted March 26, 2012 and are these values correct? Quote Link to comment https://forums.phpfreaks.com/topic/259742-help/#findComment-1331240 Share on other sites More sharing options...
spearchilduser Posted March 26, 2012 Author Share Posted March 26, 2012 No it should show a table with an entry within it as my database has a entry that matches the criteria but it is printing out the select statment correctly Quote Link to comment https://forums.phpfreaks.com/topic/259742-help/#findComment-1331244 Share on other sites More sharing options...
AyKay47 Posted March 26, 2012 Share Posted March 26, 2012 Something is not right here, if the select statement was printing out as it should, it would grab results data from the table, but it is not. Post the entire relevant code. Quote Link to comment https://forums.phpfreaks.com/topic/259742-help/#findComment-1331250 Share on other sites More sharing options...
spearchilduser Posted March 26, 2012 Author Share Posted March 26, 2012 <?php $db = mysql_connect("", "",""); mysql_select_db(""); $schemelevel = $_POST['schemelevel']; $sql = "SELECT * FROM project WHERE Module_Code = '$schemelevel' AND Available = '1'"; $result = mysql_query($sql) or die($sql .'<br />'. mysql_error()); if(mysql_num_rows($result) == 0) { echo "no results <br/ >"; echo $sql; exit; } while ($myrow = mysql_fetch_row($result)) { echo "<table border=1>\n"; echo "<tr><td>Module Code</td><td>Title</td><td>First_Supervisor</td><td>Level</td><td>Description</td></tr>\n"; echo "<tr><td><A HREF='http://students.comp.glam.ac.uk/08030472/project/displayproject.php?T1=$myrow[0]'>$myrow[0]</A></td><td>$myrow[1]</td><td>$myrow[2]</td><td>$myrow[3]</td><td>$myrow[4]</td></tr>\n"; //printf("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>\n", //echo"<A HREF='http://students.comp.glam.ac.uk/08030472/project/displayproject.php?T1=$myrow[0]'>$myrow[0]</A>"$myrow[0],$myrow[1],$myrow[2],$myrow[3],$myrow[4]); } echo "</table>\n"; ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/259742-help/#findComment-1331255 Share on other sites More sharing options...
AyKay47 Posted March 26, 2012 Share Posted March 26, 2012 then the SQL is simply not matching any results sets in the db table. Make sure the field types are correct and the values to be compared are correct etc.. Quote Link to comment https://forums.phpfreaks.com/topic/259742-help/#findComment-1331257 Share on other sites More sharing options...
PFMaBiSmAd Posted March 26, 2012 Share Posted March 26, 2012 Do you even know what data is in your table? You have changed the query from using Available = 'Yes' to using Available = '1'? What is the actual data in your database table that the query should return? Quote Link to comment https://forums.phpfreaks.com/topic/259742-help/#findComment-1331260 Share on other sites More sharing options...
cpd Posted March 26, 2012 Share Posted March 26, 2012 A complete guess but if your fields are named appropriately, isn't Module_Code a unique code for each module, not "BSc Hons". Could be completely wrong so still answer PFMaBiSmAd's question regarding what data should be returned. Quote Link to comment https://forums.phpfreaks.com/topic/259742-help/#findComment-1331264 Share on other sites More sharing options...
spearchilduser Posted March 26, 2012 Author Share Posted March 26, 2012 hi sorry yeah i put in the wrong field name god how stupid sorry for wasting tiem and thanx for the responses Quote Link to comment https://forums.phpfreaks.com/topic/259742-help/#findComment-1331353 Share on other sites More sharing options...
AyKay47 Posted March 26, 2012 Share Posted March 26, 2012 not a problem, sometimes the easiest fixes are the hardest to spot. Quote Link to comment https://forums.phpfreaks.com/topic/259742-help/#findComment-1331359 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.