Mundo Posted March 6, 2009 Share Posted March 6, 2009 if (isset($_GET['submit'])) { $result = mysql_query(sprintf("SELECT * FROM diary WHERE diary_date = '$_GET[date]' AND diary_staff = 'Matt Black'")); if($result != NULL) { echo "<h1>Matt Black</h1>"; while ($row = mysql_fetch_assoc($result)) { include "tpl/viewdiary_table.tpl"; } echo "<hr />"; } I want it to test if the query gets any results and if not, then display nothing... Doesn't seem to work though but i'm sure i've done it right?! Any help? Quote Link to comment https://forums.phpfreaks.com/topic/148273-solved-help-with-query/ Share on other sites More sharing options...
Maq Posted March 6, 2009 Share Posted March 6, 2009 I like to use: if(mysql_num_rows($result) > 0) { You should also add: or die(mysql_error()); at the end of your mysql_query. Quote Link to comment https://forums.phpfreaks.com/topic/148273-solved-help-with-query/#findComment-778395 Share on other sites More sharing options...
Mundo Posted March 6, 2009 Author Share Posted March 6, 2009 In this instance, what would be the benefit of using mysql_error()? If there is an error, it will just display nothing, surely? Oh and it worked, thanks Quote Link to comment https://forums.phpfreaks.com/topic/148273-solved-help-with-query/#findComment-778398 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.