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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:00:21+00:00 2026-06-11T09:00:21+00:00

here is my problem… i am trying to return multiple rows without refreshing the

  • 0

here is my problem… i am trying to return multiple rows without refreshing the page from my a PDO statement using the ‘LIKE’ CLAUSE, the problem is it only returns one row and not the rest…can somebody please help me? thanks in advance

Here is my html form:

<h2>Please insert the username you would like to search for</h2>

<div align="center" id="loader_div"><span id="search_result"></span></div>

<form action="send/search.php" method="post" id="search_form">
<input type="text" id="search_username" name="get_name" />
<input type="submit" name="submitsearch" />
</form>    
<div id="get_users">

</div>

My PHP is as follows:

$search = $_POST['get_name'];

$query = $db->prepare("SELECT *
                         FROM `users`
                         WHERE `users`.`username` LIKE ? LIMIT 10");

$query->bindValue(1, "%".$search."%", PDO::PARAM_STR);

try {
     $query->execute();

     $data['success'] = true;

     while($row = $query->fetch(PDO::FETCH_OBJ)) {

     $data['users'] = " ".$row->username." ";

     echo json_encode($data);   
     exit(); 
     }

} catch (PDOException $e) {
  die($e->getMessage());     
  exit();
}

And here is my jQuery to return the PHP results:

$.ajax ({
type: "POST",
url: "send/search.php",
data: $('#search_form').serialize(),
dataType: "json",
success: function(data){
        if(data.success === true)
        {
          $("#display_users").html(data.users);
        },
error: function(xhr, status, et) {

    }
});
  • 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-11T09:00:23+00:00Added an answer on June 11, 2026 at 9:00 am

    The json_encode and exit should be outside the while loop:

    while($row = $query->fetch(PDO::FETCH_OBJ)) {
    
         $data['users'] .= " ".$row->username." ";    
    }
    
    echo json_encode($data);   
    exit(); 
    

    Denpending on what format you need on the client side you decide on what to do with the $data['users'], this is also a option:

    $data['users'][] = " ".$row->username." ";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Maddening problem here. When my page loads: <body onload=getClientDateTime();> It runs this function: document.getElementById('ClientDateTime').value=hello
I have a problem here im trying to upload a file first time it
The problem here is pretty self-evident from the resulting JSON array at the bottom.
My problem here is that I would like to pass an object to a
Here my problem: @Assert\Regex( * pattern=/^[A-Za-z0-9][A-Za-z0-9\]*$/, * groups={creation, creation_logged} * ) I'm using the
here my problem, i'm using asp.net for my site, i get a list of
Here's my problem, say, for example, I have a link on my page, it
A curious problem here. I'm testing a site using IETester for Internet Explorer 8.
Here is problem I'm trying to solve. It's for logistics company. I got all
My problem here I know is bubbling within the DOM because I have multiple

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.