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

  • Home
  • SEARCH
  • 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 8198137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:53:17+00:00 2026-06-07T05:53:17+00:00

SOLVED: Datatypes in the table for country and OS were set to VARCHAR so

  • 0

SOLVED:
Datatypes in the table for country and OS were set to VARCHAR so in my where, I changed = 0 to = ‘0’.
Thanks to raina77ow for pointing this out! Appreciate it.

I’m not quite sure how to write this query. Basically, I’m going to have a table with two columns (OS and country_code) – more columns too, but those are the conditional ones. These will be either set to 0 for all, or specific ones, separated by commas.

Now, what I’m trying achieve is pull data from the table if the OS and country_code = 0, or if they contain matching data (separated by commas).

Then, I have a column for time. I want to select rows where the time is GREATER than the time column, unless the column time_t is set to false, in which case this shouldn’t matter.

I hope I explained it right?

This is what I kind of have so far:

$get = $db->prepare("SELECT * FROM commands 
    WHERE country_code = 0 OR country_code LIKE :country_code 
    AND OS = 0 OR OS LIKE :OS 
    AND IF (time_t = 1, expiry > NOW())
");
$get->execute(array(
    ':country_code' => "%{$data['country_code']}%",
    ':OS' =>  "%{$data['OS']}%"
));

EDIT: This is the code I’m using now, but I still can’t seem to get the OS and Country_code part working:

$get = $db->prepare("SELECT * FROM commands 
WHERE (country_code = 0 OR country_code LIKE :country_code) 
AND (OS = 0 OR OS LIKE :OS) 
AND (time_t <> 1 OR expiry > NOW())
");

$get->execute(array(
':country_code' => "%{$data['country_code']}%",
':OS' =>  "%{$data['OS']}%"
));

Data sent to the DB would be:
OS => Windows 7
country_code => GB
ONLY one would be being sent, not more than one. The issue I’m having right now is, it’s working for OS and for the time thing, but it’s not working for the country. I even tried a raw query, when the data in the table is “FR, SA” and I did LIKE ‘%GB%’ it still returned the row

  • 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-07T05:53:19+00:00Added an answer on June 7, 2026 at 5:53 am

    It’s a question of logical operators’ precedence: AND is higher than OR in the ladder, so your original query will be executed as…

    WHERE country_code = 0 OR (country_code LIKE ... AND OS = 0) OR OS LIKE...
    

    Use parenthesis to separate your conditions, like this:

    WHERE (country_code = 0 OR country_code LIKE ...) 
      AND ( OS = 0 OR OS LIKE ...)
    

    And the final filter condition in this query, I suppose, should be written as…

    AND ( time_t <> 1 OR expiry > NOW() )
    

    UPDATE: … and it’s actually should be country_code = '0' or something like this in your code. You’re checking the VARCHAR column, remember.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a SQL table set that looks like this create table foo (
SOLVED: Crap... why is it always you figure something out right AFTER you finally
Solved I actually found out what is going on here. Turns out it was
@Solved The two subquestions I have created have been solved (yay for splitting this
SOLVED: This is what was wrong: current.addFolder(folder); (in the final else clause of the
SOLVED I misspelled the property department -> Department. Thanks for the answers and a
what if you have so many entries in a table, that 2^32 is not
I need to be able to insert numbers like 098532 into my table. This
I can not solve this problem for a while. I would be glad for
SOLVED: The problem lies within Firefox 6.0.2 security. I have changed my URL request

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.