Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8241365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:48:43+00:00 2026-06-07T20:48:43+00:00

I have a method that returns data from a tournament system I am creating.

  • 0

I have a method that returns data from a tournament system I am creating. I have an issue where the INNER JOIN query always returns one row, not matter if the WHERE clause is true or not.

In the database there are two tournaments, both with a T.game = ‘1’ – yet if I check the query for T.game = ‘2’, it still returns a row according to mysql_num_rows(), and when I print_r() the resulting array, it is empty except for the COUNT() row, yet shouldn’t the WHERE clause not find any rows and portray this accordingly to the mysql_num_rows() ?

I guess my main question is how do i stop the COUNT(P.id) from always displaying even when there are no matched rows in the tournaments table

public function fetchTournaments($gameID){
        if($gameID == "" || $this->hasChar($gameID) || $this->hasSymb($gameID)){
            $this->_errorMsg = "Invalid Game ID.";
            return false;
        }else{
            $query = mysql_query("SELECT
                                    T.id,
                                    T.name,
                                    T.description,
                                    T.checkin,
                                    DATE_FORMAT(T.date,'%b %d, %Y @ %h:%i %p') AS date,
                                    COUNT(P.id) AS playernum
                                  FROM tournaments T
                                  INNER JOIN players P
                                  ON T.id = P.tourney_id
                                  WHERE T.game='{$gameID}'") or die(mysql_error());
            $result = mysql_num_rows($query);
            if($result > 0){
                echo $result;
                $output = mysql_fetch_array($query);
                return $output;
            }else{
                $this->_errorMsg = "There are no tournaments for this game.";
                return false;
            }

        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T20:48:45+00:00Added an answer on June 7, 2026 at 8:48 pm

    In MySQL, COUNT (like other aggregate functions) will always return a result. You may be able to get around this by using GROUP BY, which will return the results of the aggregate for each row. You might want to play with the columns you list in the GROUP BY, but maybe something like:

    $query = mysql_query("SELECT
                        T.id,
                        T.name,
                        T.description,
                        T.checkin,
                        DATE_FORMAT(T.date,'%b %d, %Y @ %h:%i %p') AS date,
                        COUNT(P.id) AS playernum
                      FROM tournaments T
                      INNER JOIN players P
                      ON T.id = P.tourney_id
                      WHERE T.game='{$gameID}'
                      GROUP BY T.id,T.name,T.description,T.checkin,date") or die(mysql_error());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a method that I call and it returns bitmap data from a
I have a data tier select method that returns a datatable. It's called from
I have a method that returns lot of data, should I use @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) for
I have a webservice method that reads a photo and returns its byte data.
I have a controller method that returns a jSON object and in one calling
I have a method that basically returns the results of a mysql query. public
I have a method that calls a Proc ad returns the data. But I
I have a OdbcDataReader that gets data from a database and returns a set
I have a method that gets data from the data manager. It looks something
I have a method that returns NSData from a CGPathRef like so ... +

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.