The14thGOD Posted March 28, 2008 Share Posted March 28, 2008 I can't seem to find the mistake in this code: <?php $com_query = "SELECT * FROM comments WHERE picID='$_GET[id]' AND status='enabled' "; $com_result = mysql_query($com_query); if(!mysql_query($com_query)) { echo "<p class=\"nocomments\">There are no comments yet.</p>"; }?> It's not echoing hi, it appears to not be getting inside that if statement. That reads if no mysql_query (meaning query returned nothing) then do this right? or have i been gone from php that long...hah Thanks in advance Justin Quote Link to comment Share on other sites More sharing options...
rhodesa Posted March 28, 2008 Share Posted March 28, 2008 Try this: <?php $com_query = "SELECT * FROM `comments` WHERE `picID`='".mysql_real_escape_string($_GET['id'])."' AND `status`='enabled'"; $com_result = mysql_query($com_query) or die("Query error: ".mysql_error()); if(mysql_num_rows($com_result)) { while($row = mysql_fetch_array($com_result)){ //Print Comments Here } }else{ echo '<p class="nocomments">There are no comments yet.</p>'; } ?> Quote Link to comment Share on other sites More sharing options...
conker87 Posted March 28, 2008 Share Posted March 28, 2008 <? if (mysql_num_rows($com_query) = 0) { echo "<p class=\"nocomments\">There are no comments yet.</p>"; }?> Quote Link to comment Share on other sites More sharing options...
The14thGOD Posted March 28, 2008 Author Share Posted March 28, 2008 Awesome, that worked rhodesa. Thank you =D I also tried conker87's way but that did not work but I appreciate the help. Thank you both for helping Quote Link to comment Share on other sites More sharing options...
Kieran Menor Posted March 28, 2008 Share Posted March 28, 2008 Just to explain what's going on, mysql_query only returns false if the query fails, which it doesn't. It simply doesn't return any rows. Quote Link to comment Share on other sites More sharing options...
conker87 Posted March 28, 2008 Share Posted March 28, 2008 Double = I meant! Blegh. Quote Link to comment Share on other sites More sharing options...
The14thGOD Posted March 28, 2008 Author Share Posted March 28, 2008 Ah, alright. I swear I've used that same code before though... ha. Oh well. Conker87, I tried that already, I noticed that wasn't right and changed it but for the reason Boom.dk said it didn't work. Thanks again, I'd hit the topic solved button but I can never find the damn thing. I found it once...haha Quote Link to comment Share on other sites More sharing options...
conker87 Posted March 28, 2008 Share Posted March 28, 2008 It's normally next tot he 'reply' button ^^ 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.