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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:14:53+00:00 2026-06-10T15:14:53+00:00

I have a php-ajax page that where user writes search string in search.php ,

  • 0

I have a php-ajax page that where user writes search string in search.php, and the list is echoed in getsearch.php. and the result of getsearch.php is show in search.php in using ajax But there is check box in every row.

getsearch.php 

$q = $_GET["q"];

$sql = "select hobbyid,hobby from hobbies where hobby LIKE '%".$q."%' ";

if($result=mysql_query($sql))
{
    while($row=mysql_fetch_assoc($result))
    { 
         $v = $row['hobbyid'];
         echo $row['hobby'] . '<input type="checkbox" name="hobby[]" value='.$v.'>';
    }
}

And you can see in following code , this sql is fired for every change(onkeyup). I have kept a check box to get array of selected hobbies. These are selected values are passed to updatehobby.php.

search.php

echo '<form action="updatehobby.php" method="POST">
echo 'Search:<input type="text"  onkeyup="showSearch(this.value)" />
<div id="txtSearch" >HERE THE RESULTS FROM getsearch.php are shown</div>
<input type="submit></form>';

So when the user writes a new search string, the list gets changed and so the previous check boxes are deselected. So how can i retain the previous check boxes and display them even if the search changes?

Ultimately after 1 day trying, I successfully did this way!

See user enters search string in search.php and the query is passed to getsearch.php and from there the results are echoed and this results are shown in search.php

So instead of using check box, i inserted a button. So every row now has a button instead of
checkbox.

<button type="button" onClick="submitform(<?php echo $row['hobbyid']; ?     >);">Add hobby</button>

Now in search.php i again used another ajax function (submitform) which handled the onclick call of button.
When the button add hobby is pressed, ajax function submitform is called and the hobby is inserted.

So basically i used two ajax functions in search.php , one ajax for searching and populating results and another for updating it to database.

  • 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-10T15:14:55+00:00Added an answer on June 10, 2026 at 3:14 pm

    (1) You may send checkboxes state in your search request and set checked/not checked in PHP code and include it in your request to database so it will be like

    "select hobbyid,hobby from hobbies
    where hobby LIKE '%".$q."%' or hobbyid in(list_of_hobbies_received_in_request) "

    than, in your loop where you render an HTML – check if id is in received array of ids and set checked state for required hobbies.

    (2) Or you can remeber checkboxes state before you send request in javascript and after response came – avoid deleting selected checkboxes and check that there is no duplicates. But it looks like that will be a big pain with how you are getting search results. So, I think (1) is what you need.

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

Sidebar

Related Questions

I have this jQuery script var dataString = class_id=+class_id; $.ajax({ type: POST, url: page.php,
Assume that I have 2 .php files : index.php and ajax.php This is index.php:
i have a php that responds to an ajax and inserts a row into
I currently have a PHP form that uses AJAX to connect to MySQL and
I have a php script that gets called via an ajax call. Values are
I have a webpage that retrieves data (via ajax/php) and shows it in an
I have page loading, via AJAX a PHP page into a div. In turn,
I have a link/button on my page that should lead the user to a
I have page where everything is completed with ajax and php. I have in-tab
If a user refreshes a page I need to send the data using php

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.