Brandon Jaeger Posted June 22, 2006 Share Posted June 22, 2006 [code]$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM forum_topics WHERE forumid = '" . $fid . "' AND pinned = '0' ORDER BY id ASC"),0) or die(red_message("An error has occurred") . "<br \>" . red_message(mysql_error() ? mysql_error() : "No MySQL error to show") . "<br \>ID: 1");[/code]You can ignore everything after "or".It doesn't give me an error message from mysql_error(). Also there's 1 row in the table "forum_topics" where [b]pinned[/b] is "1". If I set [b]pinned[/b] to "0" it works fine.So what I want to know is why doesn't it work when I have one topic in the forum where [b]pinned[/b] is "1"? I know I have [b]WHERE pinned = '0'[/b] in the query itself, but I just don't understand it.If someone could provide a solution I'd greatly appreciate it!Thanks in advance.---brandonEdit: I've found a solution for it by checking if there's any rows first, then if so, do mysql_result:[code] $query = "SELECT * FROM forum_topics WHERE forumid = '" . $fid . "' AND pinned = '0'"; $result = mysql_query($query) or die(red_message(mysql_error())); if(mysql_num_rows($result) > 0) { // BUILD LINKS $total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM forum_topics WHERE forumid = '" . $fid . "' AND pinned = '0' ORDER BY id ASC"),0) or die(red_message("An error has occurred") . "<br \>" . red_message(mysql_error() ? mysql_error() : "No MySQL error to show") . "<br \>ID: 1"); $total_pages = ceil($total_results / $max_results); [/code]Is there another way though? Quote Link to comment https://forums.phpfreaks.com/topic/12620-whats-wrong-with-this/ Share on other sites More sharing options...
smartDa Posted June 22, 2006 Share Posted June 22, 2006 [!--quoteo(post=386765:date=Jun 22 2006, 02:29 AM:name=v3x)--][div class=\'quotetop\']QUOTE(v3x @ Jun 22 2006, 02:29 AM) [snapback]386765[/snapback][/div][div class=\'quotemain\'][!--quotec--][code]$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM forum_topics WHERE forumid = '" . $fid . "' AND pinned = '0' ORDER BY id ASC"),0) or die(red_message("An error has occurred") . "<br \>" . red_message(mysql_error() ? mysql_error() : "No MySQL error to show") . "<br \>ID: 1");[/code]You can ignore everything after "or".It doesn't give me an error message from mysql_error(). Also there's 1 row in the table "forum_topics" where [b]pinned[/b] is "1". If I set [b]pinned[/b] to "0" it works fine.So what I want to know is why doesn't it work when I have one topic in the forum where [b]pinned[/b] is "1"? I know I have [b]WHERE pinned = '0'[/b] in the query itself, but I just don't understand it.If someone could provide a solution I'd greatly appreciate it!Thanks in advance.---brandonEdit: I've found a solution for it by checking if there's any rows first, then if so, do mysql_result:[code] $query = "SELECT * FROM forum_topics WHERE forumid = '" . $fid . "' AND pinned = '0'"; $result = mysql_query($query) or die(red_message(mysql_error())); if(mysql_num_rows($result) > 0) { // BUILD LINKS $total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM forum_topics WHERE forumid = '" . $fid . "' AND pinned = '0' ORDER BY id ASC"),0) or die(red_message("An error has occurred") . "<br \>" . red_message(mysql_error() ? mysql_error() : "No MySQL error to show") . "<br \>ID: 1"); $total_pages = ceil($total_results / $max_results); [/code]Is there another way though?[/quote]First why do you have Arithmetic parameters in "" quote? As an integer, the 0 value is mathematically operable. Putting it in quote simply vabous it and will not carry out any incre/decrement on it. Quote Link to comment https://forums.phpfreaks.com/topic/12620-whats-wrong-with-this/#findComment-48438 Share on other sites More sharing options...
Brandon Jaeger Posted June 22, 2006 Author Share Posted June 22, 2006 What part are you talking about?P.S. It works fine. Quote Link to comment https://forums.phpfreaks.com/topic/12620-whats-wrong-with-this/#findComment-48465 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.