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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:34:05+00:00 2026-06-06T16:34:05+00:00

I am having trouble with the LIKE statement in my query in MYSQLI. It

  • 0

I am having trouble with the LIKE statement in my query in MYSQLI. It seems like it is not finding any terms that would go into the LIKE statement. I am trying to bind the parameters into the LIKE statement but my question is that am I setting up the LIKE statement in mysqli incorrectly?

The strange thing is that if I output the query and insert it into SQL, and just change the ‘?’ to a term such as ‘%AAB%’, it works fine in SQL as the it does display the records consisting the term AAB. The problem is that it is not working in PHP,mysqli as that it is not showing any records at all if I type in AAB in the textbox. It keeps stating “Sorry, No Question were found from the Search”.
Does anybody know why this is?

Below is the code (I have connected to db using mysqli):

<form action="previousquestions.php" method="get">
<p>Search: <input type="text" name="questioncontent" value="<?php echo isset($_GET['questioncontent']) ? $_GET['questioncontent'] : ''; ?>" onchange="return trim(this)" /></p>
      <p><input id="searchquestion" name="searchQuestion" type="submit" value="Search" /></p>
      </form>


<?php 

if (isset($_GET['searchQuestion'])) {

$searchquestion = $_GET['questioncontent'];
$terms = explode(" ", $searchquestion);

$questionquery = "SELECT q.QuestionContent FROM Question q WHERE ";

$i=0;

$whereArray = array();
$orderByArray = array();
$orderBySQL = "";
$paramString = "";

//loop through each term


 foreach ($terms as $each) {
    $i++;
    $whereArray[] = $each;
    $orderByArray[] = $each; 
    $paramString .= 'ss';
    //if only 1 term entered then perform this LIKE statement
    if ($i == 1){
        $questionquery .= "q.QuestionContent LIKE CONCAT('%', ?, '%') ";
    } else {
        //If more than 1 term then add an OR statement
        $questionquery .= "OR q.QuestionContent LIKE CONCAT('%', ?, '%') ";
        $orderBySQL .= ",";
    }

    $orderBySQL .= "IF(q.QuestionContent LIKE CONCAT('%', ?, '%') ,1,0)";

}  

$questionquery .= "GROUP BY q.QuestionId, q.SessionId ORDER BY " . $orderBySQL;
$questionquery .= " DESC ";
$stmt=$mysqli->prepare($questionquery)or die($mysqli->error); 

function makeValuesReferenced(&$arr){ 
    $refs = array(); 
    foreach($arr as $key => $value) 
        $refs[$key] = &$arr[$key]; 
    return $refs; 

}

$ref = array_merge((array)$paramString, $whereArray, $orderByArray);
call_user_func_array(array($stmt, 'bind_param'), makeValuesReferenced($ref));


    $stmt->execute();
    $stmt->bind_result($dbQuestionContent); 
    $questionnum = $stmt->num_rows();

        if($questionnum ==0){
    echo "<p>Sorry, No Questions were found from this Search</p>";
    }
    else{

      $output = "";
        while ($stmt->fetch()) {
$output .= "
      <tr>
      <td class='questiontd'>$dbQuestionContent</td>
      </tr>";
        }
        $output .= "        </table>";

        echo $output;

  }


?> 
  • 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-06T16:34:07+00:00Added an answer on June 6, 2026 at 4:34 pm

    It looks like mysqli is escaping your % characters, or something equivalent is happening as part of the client/server communication. Try this:

    foreach ($terms as $each) {
        $i++;
        $whereArray[] = $each;
        $orderByArray[] = $each; 
        $paramString .= 'ss';
        //if only 1 term entered then perform this LIKE statement
        if ($i == 1){
            $questionquery .= "q.QuestionContent LIKE CONCAT('%', ?, '%') ";
        } else {
            //If more than 1 term then add an OR statement
            $questionquery .= "OR q.QuestionContent LIKE CONCAT('%', ?, '%') ";
            $orderBySQL .= ",";
        }
        $orderBySQL .= "IF(q.QuestionContent LIKE CONCAT('%', ?, '%') ,1,0)"; 
    }
    

    You do realize your ORDER BY clause is doing absolutely nothing useful, right?

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

Sidebar

Related Questions

I'm having trouble finding the syntax for a statement (or whether or not it's
I'm not having trouble with the output I get output that looks like this
i'm having trouble trying to define this function-like macro, which takes 4 vector magnitudes
I'm having trouble going from finding each view based on its actual id like
I'm having trouble incorporating a bit of logic into a large SQL query. I'm
I am having trouble writing a typeof statement which would be using a variable
I am having trouble testing and automating conditional matchMedia statements. I would like to
I'm having a little trouble (more like an annoyance, really) when using the Play
I am having trouble writing and reading back special characters like the Euro-sign (€)
I am having trouble using a NSString with unicode characters like 'ç' and 'ñ'.

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.