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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:20:54+00:00 2026-06-01T06:20:54+00:00

I have form like this: <form method=POST action=<?php echo base_url() ?>admin/admin_search> <fieldset> <label for=nalozi>Nalozi</label><input

  • 0

I have form like this:

<form method="POST" action="<?php echo base_url() ?>admin/admin_search">
    <fieldset>
        <label for="nalozi">Nalozi</label><input type="checkbox" name="nalozi" />
        <label for="malio_glasi">Mali oglasi</label><input type="checkbox" name="mali_oglasi" />
        <label for="zute_strane">Zute strane</label><input type="checkbox" name="zute_strane" />
        <label for="berza_rada">Berza rada</label><input type="checkbox" name="berza_rada" />
        <label for="vesti">Vesti</label><input type="checkbox" name="vesti" />
        <label for="event">Dogadjaji</label><input type="checkbox" name="event" />
    </fieldset>      

    <input type="search" name="keyword" id="keyword" />
    <input type="submit" value="Trazi"/>
</form>

and PHP code for searching:

function admin_search(){

        $keyword = trim($_POST['keyword']);
        $search_explode = explode(" ", $keyword);
        $x = 0;

        $mgs = isset($_POST['mali_oglasi']) ? 1 : "";
        $jbs = isset($_POST['berza_rada']) ? 2 : "";
        $nws = isset($_POST['vesti']) ? 3 : "";
        $ypg = isset($_POST['zute_strane']) ? 4 : "";        

        if($mgs != "" || $jbs != "" || $nws != "" || $ypg != ""){$or = " OR ";}else{$or = "";}
        if($jbs != "" || $nws != "" || $ypg != "" ){$or1 = " OR ";}else{$or1 = "";}
        if($nws != "" || $ypg != "" ){$or2 = " OR ";}else{$or2 = "";}
        if($ypg != "" ){$or3 = " OR ";}else{$or3 = "";}

        $nlz = isset($_POST['nalozi']) ? "person" : "";
        $dgj = isset($_POST['event']) ? "event" : "";

        if($nlz != "" || $dgj != ""){$z = ", "; $or_like = " OR "; }else{$z = " "; $or_like = "";}
        if($dgj != ""){$z1 = ", ";$or_like1 = " OR ";}else{$z1 = " ";$or_like1 = "";}

        if($mgs != "" || $ypg != "" || $jbs != "" || $nws != ""){$gi = "global_info";}else{$gi = "";}

        $sql = "SELECT * FROM ";

        if($gi != ""){$sql .= " $gi $z";}
        if($nlz != ""){$sql .= " $nlz $z1";}
        if($dgj != ""){$sql .= " $dgj";}

        $sql .= " WHERE ";
        if($mgs != ""){$sql .= " global_info.info_type_id = {$mgs} $or1 ";}        
        if($jbs != ""){$sql .= " global_info.info_type_id = {$jbs} $or2 ";}        
        if($nws != ""){$sql .= " global_info.info_type_id = {$nws} $or3 ";}        
        if($ypg != ""){$sql .= " global_info.info_type_id = {$ypg} ";}
        $sql .= " AND ";
        foreach($search_explode as $each){
            $x++;
            if($x == 1){
                if($gi != ""){$sql .= " global_info.name LIKE '%$each%' $or_like ";}   
                if($nlz != ""){$sql .= " $nlz.name LIKE '%$each%'$or_like1 ";}   
                if($dgj != ""){$sql .= " $dgj.name LIKE '%$each%' ";}   

            } else {

                $sql .= " AND global_info.name LIKE '%$each%' ";
            }
        }
        echo $sql;        
        $q = $this->db->query($sql);
        echo $q->num_rows();
        return $q = $q->num_rows() == 0 ? FALSE :  $q->result_array();
    }

Idea behind this search – I must be able to choose witch tables I want to search and the search by the keyword(s) need to work for any table choosen.

When one of the checkboxes is checked, it is working fine, but if two or more are checked, and if there is more than one keyword (for the moment I am trying just global_info table with two or more keywords), function is working fuzzy. Sometimes it does not work, or if it is working it is giving same results multiple times, or everything except the keyword. At the moment I don’t quite understand why it is giving results that it is giving. How to make this work?

  • 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-01T06:20:56+00:00Added an answer on June 1, 2026 at 6:20 am

    Try changing it to read like this:

    $tables = array();
    if(isset($_POST['mali_oglasi'])){
        $tables['mgs'] = 1;
    }
    /* 
     repeat for the other tables 
    */
    
    /* Where you're building your WHERE clause, use this instead of the 'OR' logic */
    if(!empty($tables)){
        $sql .= 'global_info.info_type_id IN (' . implode(',',$tables) . ')';
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

so I have a simple login page like this: <fieldset> <legend>Verification</legend> <form method=post action=authentication.php>
I have a php form like this. <form name=form1 id=mainForm method=postenctype=multipart/form-data action=<?php echo $_SERVER['PHP_SELF'];?>>
I have a form like this: <form method=post action=> <?php $h = mysql_query(select distinct
On the page 'selecteditems.php' I have a form like this: <form method=POST name=selecteditems action=nextpage.php>
I have a simple form like this: <form name=serachForm method=post action=/home/search> <input type=text name=searchText
I have a form like this: <form id=loginCompact action=https://externalsite... name=sportsbook method=post onsubmit=createCookie('BRLOG', document.sportsbook.username.value, 1)>
So I have this code: <form name=form action=./ method=post> <input type=file name=newfile id=newfile />
im trying to achieve the following, in php i have a form like this:
I have a form like this: <form name=mine> <input type=text name=one> <input type=text name=two>
I have a form that looks like this: class SampleForm(forms.Form): text = forms.CharField(max_length=100) In

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.