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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:44:04+00:00 2026-06-03T08:44:04+00:00

I am using keyup() function to send the variable to a php page (consult.php)

  • 0

I am using keyup() function to send the variable to a php page (consult.php) that has the mysql select to bring my search result.

index.php

<html>
<head>
<script type="text/javascript" src="jquery-1.7.2.min.js"></script>
<script type="text/javascript">
$(function(){
 $('#input').keyup(function(){
  var inputVal=$('#input').val();
  $.ajax({
   type: 'POST',
   data: ({word : inputVal}),
   url: 'consult.php',
   success: function(data) {
    $('#content').html(data);
   }
  });
 });
 $("#menu li").click(function(){
  $.ajax({
   type: 'POST',
   data: ({word : inputVal}),
   url: 'consult.php',
   success: function(data) {
    $('#content').html(data);
  }
  });
 });
});
</script>
<style>
 #menu ul{
  margin:0;
  padding:0;
  list-style:none;
 }
 #menu ul li{
  padding:5px;
  margin-right:2px;
  float:left;
  border:#00F solid 1px;
  background-color:#faa8ad;
}
</style>
</head>
<body>
 <div>Write<br>
  <input type="text" id="input" name="input"/>
 </div>
<div id="content"></div>
</body>
</html>

consult.php

<?
 include('conn.php');
 $word = isset($_POST['word']) ? $_POST['word'] : $_GET['word'];
 if($word){

  $perPag = 4;
  $query = mysql_query("SELECT COUNT(carro_id) FROM carros WHERE carro_modelo LIKE '$word%'");
  $totalResult = ceil(mysql_result($query, 0)/$perPag);

  $pag = (isset($_GET['pag']) and (int)$_GET['pag'] > 0) ? (int)$_GET['pag'] : 1;
  $ini = ($pag - 1) * $perPag;

  $queryTotal = mysql_query("SELECT carro_modelo FROM carros WHERE carro_modelo LIKE '$word%' ORDER BY carro_id LIMIT $ini, $perPag");
      while($row = mysql_fetch_assoc($queryTotal)){
       echo "<div>".$row['carro_modelo']."</div>";
      }
  if($totalResult >= 1 && $pag <= $totalResult){
   for($i = 1; $i <= $totalResult; $i++){
    echo($i == $pag) ? '<div id="menu"><ul><li><strong><a href="?pag='.$i.'&word='.$word.'">'.$i.'</a></strong></li></ul></div> ' : '<div id="menu"><ul><li><a href="?pag='.$i.'&word='.$word.'">'.$i.'</a></li></ul></div> ';
   }
  }
 }else{
  $queryTotalReult = mysql_query("SELECT * FROM carros");
  while($rowTotal = mysql_fetch_assoc($queryTotalReult)){
   echo "<div>".$rowTotal['carro_modelo']."</div>";
  }
 }
?>

The problem is, when i click in the links of the pagination its load back the result in the index.php bringing all results again ignoring the search.

thank you in advance!

  • 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-03T08:44:05+00:00Added an answer on June 3, 2026 at 8:44 am

    index.php

    <html>
    <head>
    <script type="text/javascript" src="jquery-1.7.2.min.js"></script>
        <script type="text/javascript">
    function ajaxCall(inPage,inWord)
    {
    
          $.ajax({
           type: 'POST',
           data: ({word : inWord, pag : inPage}),
           url: 'consult.php',
           success: function(data) {
            $('#content').html(data);
           }});
    }
        $(function(){
         $('#input').keyup(function(){
          var inputVal=$('#input').val();
          $.ajax({
           type: 'POST',
           data: ({word : inputVal}),
           url: 'consult.php',
           success: function(data) {
            $('#content').html(data);
           }
          });
         });
        });
        </script>
        <style>
         #menu ul{
          margin:0;
          padding:0;
          list-style:none;
         }
         #menu ul li{
          padding:5px;
          margin-right:2px;
          float:left;
          border:#00F solid 1px;
          background-color:#faa8ad;
        }
        </style>
        </head>
        <body>
         <div>Write<br>
          <input type="text" id="input" name="input"/>
         </div>
        <div id="content"></div>
        </body>
        </html>
    

    consult.php

    <?
     include('conn.php');
     $word = isset($_POST['word']) ? $_POST['word'] : $_GET['word'];
     if($word){
      $perPag = 4;
      $query = mysql_query("SELECT COUNT(carro_id) FROM carros WHERE carro_modelo LIKE '$word%'");
      $totalResult = ceil(mysql_result($query, 0)/$perPag);
      $pag = (isset($_GET['pag']) and (int)$_GET['pag'] > 0) ? (int)$_GET['pag'] : 1;
      $ini = ($pag - 1) * $perPag;
      $queryTotal = mysql_query("SELECT carro_modelo FROM carros WHERE carro_modelo LIKE '$word%' ORDER BY carro_id LIMIT $ini, $perPag");
          while($row = mysql_fetch_assoc($queryTotal)){
           echo "<div>".$row['carro_modelo']."</div>";
          }
      if($totalResult >= 1 && $pag <= $totalResult){
       for($i = 1; $i <= $totalResult; $i++){
        echo($i == $pag) ? '<div id="menu"><ul><li><strong><a onclick="ajaxCall('.$i.',\''.$word.'\')">'.$i.'</a></strong></li></ul></div> ' : '<div id="menu"><ul><li><a onclick="ajaxCall('.$i.',\''.$word.'\')">'.$i.'</a></li></ul></div> ';
       }
      }
     }else{
      $queryTotalReult = mysql_query("SELECT * FROM carros");
      while($rowTotal = mysql_fetch_assoc($queryTotalReult)){
       echo "<div>".$rowTotal['carro_modelo']."</div>";
      }
     }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have page that creates a table: http://gupii.co.uk/rap/weekTable.php and I'm using a plugin to
How to send triimed data using $.get() see code snippet below: $(#txtSearch).keyup(function() { $.get(/controller/method/,
Using PHP, I can convert MySQL data or static table data to csv, Excel,
I want to capitalize all words in an input (using keyup function) to format
Im using this code to restrict the user to not enter special characters $(input).keyup(function(){
I'm using Jquery and Ajax function to get data from MySql and put it
I have the following code to count and trigger some functions using jQuery: jQuery('#input_guideName').keyup(function(e)
I'm using this code to search trough about 500 li tags. $(function() { $.expr[:].containsInCaseSensitive
I'm building a calculator, and am using the following: jQuery(function($) { $('#Quantity').keyup(function() { console.log($(this).val());
I'm using the jQuery AJAX function in order to retrieve data from my mySQL

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.