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 8065457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:40:18+00:00 2026-06-05T11:40:18+00:00

God damn confused at the syntax for my MYSQL query. Is this correct… Can’t

  • 0

God damn confused at the syntax for my MYSQL query.

Is this correct… Can’t find an entry in internet similar to it.

$query_game_string = '';

while($game = mysql_fetch_assoc($get_game_list)){
    $query_game_string .= ' OR target = "' . $game['id'] . '" AND ancestors = "0"';   
}

echo '' . $query_game_string . '';  

//prints: OR target = "11" AND ancestors = "0" OR target = "12" AND ancestors = "0" OR target = "27" AND ancestors = "0" OR target = "29" AND ancestors = "0" OR target = "32" AND ancestors = "0"


        $database->connect(); 

            $comments = mysql_query(
                'SELECT * 
                    FROM ' . $database->db_prefix . 'comments 
                        WHERE user_id = "' . $user->user_object["id"] . '"' .
                        $query_game_string . '                                    
                        ORDER BY created DESC'
            , $database->connection_handle);                     

        $database->close();

So the actual query would be in total:

'SELECT * 
    FROM ' . $database->db_prefix . 'comments 
        WHERE user_id = "' . $user->user_object["id"] . '"' .
        'OR target = "11" AND ancestors = "0" OR target = "12" AND ancestors = "0" OR target = "27" AND ancestors = "0" OR target = "29" AND ancestors = "0" OR target = "32" AND ancestors = "0"' . '                                    
        ORDER BY created DESC'

Is the syntax okay?

  • 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-05T11:40:20+00:00Added an answer on June 5, 2026 at 11:40 am

    Don’t know exactly what your are looking for but probably you need parenthesis:

    OR (target = "11" AND ancestors = "0")
    OR (target = "12" AND ancestors = "0")
    OR (target = "27" AND ancestors = "0")
    OR (target = "29" AND ancestors = "0")
    OR (target = "32" AND ancestors = "0")
    

    php to achieve that:

    while($game = mysql_fetch_assoc($get_game_list))
    {
        $query_game_string .= ' OR (target = "' . $game['id'] . '" AND ancestors = "0")';   
    }
    

    a way to simplify the query is using IN operand

     OR target IN("11","12","27","29","32") AND ancestors = "0"
    

    php:

    $targets = array();
    while($game = mysql_fetch_assoc($get_game_list))
    {
        $targets[] = '"'.$game['id'].'"';   
    }
    $query_game_string = ' OR target IN (' . implode(",",$targets) . ') AND ancestors = "0"';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

some comments here have confused me! I thought I knew this and god knows
God I hate the term code smell, but I can't think of anything more
My God, EF is so frustrating. I can't seem to be able to get
Really wish i was God, then I would understand what this means: The element
God i feel like i'm spamming stackoverflow, this is my 3rd post for today.
Oh god this must be so simple. I have a heading in range (0,
I just cannot work this out. My god it's making my brain hurt, so
This might be a god awful question but I'm not sure why it won't
This is one of those 'oh my god' moments. The previous programmer in our
This would be easier with a jsfiddle, but as god is my witness something

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.