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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:28:23+00:00 2026-05-27T17:28:23+00:00

$searchParams is actually an array which -if all the options are turned on looks

  • 0

$searchParams is actually an array which -if all the options are turned on looks like this

[q] => 77 [enhanced] => Y [no_subjects] => Y [visible] => Y  

the user can change it so that the enhanced option might or might not be turned on….etc…

depending on that the look of the array will change

[q] => 77 [enhanced] => N [no_subjects] => N [visible] => N

etc…

public function getWebBookBasicSearchByParams($searchParams){
            $q = $searchParams['q'];
            $fields = "`bw`.`id`,`bw`.`isbn`,`bw`.`book_title`,`bw`.`edited_by`,`bw`.`book_schedule_date`,`bw`.`downloaded_num`,`bw`.`visible_online`,`snr`.`subject_id`";
            $join= "LEFT JOIN {$this->_t_subjects_relations} snr ON (bw.id = snr.object_id and snr.type ='bookweb') ";
            $counter=0;
            $add="";
        if (isset($searchParams['q']) && !empty($searchParams['q'])) {

            if($searchParams['no_subjects'] == 'Y'){
                $add.= " snr.subject_id = NULL";
                $counter ++;
            }
            if($searchParams['enhanced'] == 'Y'){
                $add.= " MATCH(bw.description1,bw.about_the_book) AGAINST ('{$q}'IN BOOLEAN MODE)";
                $counter++;
            }
            if($searchParams['visible'] == 'Y'){
                $add.= " bw.visible_online = 1";
                $counter++;
            }
            if($searchParams['visible'] == 'N'){
                $add.= " bw.visible_online = 0";
                $counter++;
            }
            $inCopula = ($counter > 0) ? " AND" : " " ;
            $extCopula = ($counter > 0) ? "WHERE " : " " ;
        }

        $query = "SELECT {$fields} FROM {$this->_t_books_web} bw {$join}{$extCopula}{$add}";

with this code I get this $query

SELECT `bw`.`id`,`bw`.`isbn`,`bw`.`book_title`,`bw`.`edited_by`,`bw`.`book_schedule_date`,`bw`.`downloaded_num`,`bw`.`visible_online`,`snr`.`subject_id` FROM `books_web` bw LEFT JOIN `subjects_new_relations` snr ON (bw.id = snr.object_id and snr.type ='bookweb') 
AND snr.subject_id = NULL
MATCH(bw.description1,bw.about_the_book) AGAINST ('77'IN BOOLEAN MODE) bw.visible_online = 1

obviously it is wrong, and it should look like this

SELECT `bw`.`id`,`bw`.`isbn`,`bw`.`book_title`,`bw`.`edited_by`,`bw`.`book_schedule_date`,`bw`.`downloaded_num`,`bw`.`visible_online`,`snr`.`subject_id` FROM `books_web` bw LEFT JOIN `subjects_new_relations` snr ON (bw.id = snr.object_id and snr.type ='bookweb') 
**WHERE**(snr.subject_id = NULL **AND**
MATCH(bw.description1,bw.about_the_book) AGAINST ('77'IN BOOLEAN MODE) **AND** bw.visible_online = 1)

How would you modify the code above in order to get the desired mysql query, thank you for your help!

  • 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-27T17:28:24+00:00Added an answer on May 27, 2026 at 5:28 pm

    Just use an array to store all your criteria and use implode to aggregate them.

    public function getWebBookBasicSearchByParams($searchParams){
                    $q = $searchParams['q'];
                    $where = array();
                    $fields = "`bw`.`id`,`bw`.`isbn`,`bw`.`book_title`,`bw`.`edited_by`,`bw`.`book_schedule_date`,`bw`.`downloaded_num`,`bw`.`visible_online`,`snr`.`subject_id`";
                    $join= "LEFT JOIN {$this->_t_subjects_relations} snr ON (bw.id = snr.object_id and snr.type ='bookweb') ";
                    $counter=0;
                    $add="";
                if (isset($searchParams['q']) && !empty($searchParams['q'])) {
    
                    if($searchParams['no_subjects'] == 'Y'){
                        $where[] = "snr.subject_id = NULL";
                        $counter ++;
                    }
                    if($searchParams['enhanced'] == 'Y'){
                        $where[] = " MATCH(bw.description1,bw.about_the_book) AGAINST ('{$q}'IN BOOLEAN MODE)";
                        $counter++;
                    }
                    if($searchParams['visible'] == 'Y'){
                        $where[] = " bw.visible_online = 1";
                        $counter++;
                    }
                    if($searchParams['visible'] == 'N'){
                        $where[] = " bw.visible_online = 0";
                        $counter++;
                    }
                    $inCopula = ($counter > 0) ? " AND" : " " ;
                    $extCopula = ($counter > 0) ? "WHERE " : " " ;
                }
    
                $query = "SELECT {$fields} FROM {$this->_t_books_web} bw {$join}{$extCopula} WHERE " . implode(' AND ', $where);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a search form that the user can search for an Article content
So i've got a user control called TagFilter which has 2 repeaters. The control
I'm using Thinking Sphinx for full-text search, following this video . I'd like to
I am trying to do something like this: if params[:q] loc = Geocoder.search(params[:q])[0] logger.info
I have a Technique model which belongs_to User and is indexed by Thinking Sphinx.
I've got an ASP.net search page where the user can enter one or more
EDIT Looks like I figured it out - I had to call paginate after
How can I unit test a method which uses a session object inside of
I'm writing a routine to invoke methods, found by a name and an array
I am using search logic to filter results on company listing page. The user

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.