Jump to content


Photo

What's wrong with this?


  • Please log in to reply
2 replies to this topic

#1 Brandon Jaeger

Brandon Jaeger
  • Members
  • PipPipPip
  • Advanced Member
  • 155 posts
  • LocationPA
  • Age:25

Posted 22 June 2006 - 07:29 AM

$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");
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 pinned is "1". If I set pinned 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 pinned is "1"? I know I have WHERE pinned = '0' 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.

---brandon

Edit: I've found a solution for it by checking if there's any rows first, then if so, do mysql_result:
            $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);
Is there another way though?
PHP is my friend (=

#2 smartDa

smartDa
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 22 June 2006 - 12:15 PM

[!--quoteo(post=386765:date=Jun 22 2006, 02:29 AM:name=v3x)--][div class=\'quotetop\']QUOTE(v3x @ Jun 22 2006, 02:29 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
$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");
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 pinned is "1". If I set pinned 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 pinned is "1"? I know I have WHERE pinned = '0' 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.

---brandon

Edit: I've found a solution for it by checking if there's any rows first, then if so, do mysql_result:
            $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);
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.


#3 Brandon Jaeger

Brandon Jaeger
  • Members
  • PipPipPip
  • Advanced Member
  • 155 posts
  • LocationPA
  • Age:25

Posted 22 June 2006 - 02:45 PM

What part are you talking about?

P.S. It works fine.
PHP is my friend (=




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users