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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:36:36+00:00 2026-05-26T17:36:36+00:00

Maybe I am having a mind block here but I cant seem to get

  • 0

Maybe I am having a mind block here but I cant seem to get an AND clause to work properly in this query. I only want to return results where tbl_mod_Lessons.Approved = 1.

$sql = "SELECT *, 
                (SELECT AVG(intRating) FROM tbl_mod_LessonReviews LR WHERE LR.intLessonID = LS.intLessonID) rating,
                (SELECT strContentArea FROM tbl_mod_ContentAreas CA WHERE CA.intCAID = LS.intContentAreaID) strContentArea
            FROM tbl_mod_Lessons LS
            WHERE 
                (LS.strTitle LIKE $search_string) OR
                (LS.strStandards LIKE $search_string) OR
                (LS.strDescription LIKE $search_string) OR
                (LS.strActivities LIKE $search_string) OR
                EXISTS(SELECT strContentArea FROM   tbl_mod_ContentAreas CA WHERE CA.intCAID = LS.intContentAreaID AND (CA.strContentArea LIKE $search_string))
                AND (LS.Approved = 1)
            ORDER BY ".$pager->getOrder("LS.intLessonID DESC")."
            LIMIT ".$pager->PageLimits();

as you can see iv tried to add it in, this does not break the query but its returning results where Approved = 0 .

  • 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-05-26T17:36:37+00:00Added an answer on May 26, 2026 at 5:36 pm

    Try the one below. I added some brackets around your OR clauses.

    $sql = "SELECT *, 
                    (SELECT AVG(intRating) FROM tbl_mod_LessonReviews LR WHERE LR.intLessonID = LS.intLessonID) rating,
                    (SELECT strContentArea FROM tbl_mod_ContentAreas CA WHERE CA.intCAID = LS.intContentAreaID) strContentArea
                FROM tbl_mod_Lessons LS
                WHERE (
                        (LS.strTitle LIKE $search_string) OR
                        (LS.strStandards LIKE $search_string) OR
                        (LS.strDescription LIKE $search_string) OR
                        (LS.strActivities LIKE $search_string) OR
                        EXISTS(SELECT strContentArea FROM   tbl_mod_ContentAreas CA WHERE CA.intCAID = LS.intContentAreaID AND (CA.strContentArea LIKE $search_string))
                    )
                    AND (LS.Approved = 1)
                ORDER BY ".$pager->getOrder("LS.intLessonID DESC")."
                LIMIT ".$pager->PageLimits();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Maybe I'm having a bad day, but I can't seem to combine these 2
Im having issues getting this to work, maybe its not even possible? I have
Maybe I'm just thinking about this too hard, but I'm having a problem figuring
I know this maybe a very basic question but I'm having a bit of
I know that maybe this question has been asked before, but I can't seem
Maybe I'm having a really bad day, but could someone possibly help me to
Maybe I am having a moment of 'afternoon', but can anyone explain why I
Maybe you can help me with a problem I am having. The URL of
I'm having trouble groking something in Linq - maybe someone can give me some
I am having a strange problem, maybe something to do with Apache more than

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.