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 Link to comment https://forums.phpfreaks.com/topic/98304-mysql_query-not-working/ 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>'; } ?> Link to comment https://forums.phpfreaks.com/topic/98304-mysql_query-not-working/#findComment-503011 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>"; }?> Link to comment https://forums.phpfreaks.com/topic/98304-mysql_query-not-working/#findComment-503012 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 Link to comment https://forums.phpfreaks.com/topic/98304-mysql_query-not-working/#findComment-503025 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. Link to comment https://forums.phpfreaks.com/topic/98304-mysql_query-not-working/#findComment-503029 Share on other sites More sharing options...
conker87 Posted March 28, 2008 Share Posted March 28, 2008 Double = I meant! Blegh. Link to comment https://forums.phpfreaks.com/topic/98304-mysql_query-not-working/#findComment-503031 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 Link to comment https://forums.phpfreaks.com/topic/98304-mysql_query-not-working/#findComment-503034 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 ^^ Link to comment https://forums.phpfreaks.com/topic/98304-mysql_query-not-working/#findComment-503042 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.