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

  • Home
  • SEARCH
  • 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 4095198
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T19:51:35+00:00 2026-05-20T19:51:35+00:00

* *Updated code as of 3-28 Index.php <!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN

  • 0

**Updated code as of 3-28

Index.php

   <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>jQuery Search Demonstration</title>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
    <script type="text/javascript">
         $(document).ready(function(){
            $(".keywords").keyup(function(){
                $('#key').html($(this).val());
                $('#table').html($('.table:checked').val());

                // Do the ajax call
                // Get the textbox value: $(this).val()
                // Get the radio value: $('.table:checked').val()

                /*$.post("search.php", { keywords: $(".keywords").val() }, function(data){
                    $("div#content").empty()
                    $.each(data, function(){
                        $("div#content").append("- <a href='prof.php?pID=" + this.pID + "'>" + this.last + "</a>");
                    });
                }, "json");*/
            });
        });
    </script>
    </head>
    <body>
    Search by:
    <input type="radio" name="table" class="table" value="Table 1" />Professor<br />
    <input type="radio" name="table" class="table" value="Table 2" />Department<br />
    <input type="radio" name="table" class="table" value="Table 3" />Course<br />

    <input type="text" name="search" class="keywords">
    <input type="submit" name="submit" class="search">
    <div id="content">
    </div>
    </body>
    </html>

Search.php

<?php
$link = mysql_connect('##',"##","##");
mysql_select_db("###", $link);

$keywords = mysql_real_escape_string( $_POST["keywords"] );

$query = mysql_query("SELECT pID, lname, fname 
                                    FROM Professor 
                                    WHERE CONCAT(lname,fname) LIKE '%". $keywords . "%'");

$arr = array();
while( $row = mysql_fetch_array ( $query ) )
{
    $arr[] = array( "pID" => $row["pID"], "last" => $row["lname"], "first" => $row["fname "] );
}

echo json_encode( $arr );
?>

Sql for each selection:
[Professor]

SELECT pID, lname, fname 
                                    FROM Professor 
                                    WHERE CONCAT(lname,fname) LIKE '%". $keywords . "%'";

[Department]

SELECT prefix, code 
                                    FROM Department 
                                    WHERE name LIKE '%". $keywords . "%'";

[course]

SELECT prefix, code
FROM Course
WHERE CONCAT(prefix,course) LIKE ‘%”. $keywords . “%'”;

  • 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-05-20T19:51:36+00:00Added an answer on May 20, 2026 at 7:51 pm

    You should change your query like this:

    $query = mysql_query("SELECT pID, lname, fname 
                                        FROM Professor 
                                        WHERE CONCAT(lname,fname) LIKE '%". $keywords . "%'");
    

    Please make sure this these fields in json and javascript are the same:

    $arr[] = array( "id" => $row["pID"], "last" => $row["lname"], "first" => $row["fname"] );
    
    $("div#content").append("- <a href='post.php?id=" + this.id + "'>" + this.first + " " + this.last + "</a>");
    

    HTML code:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>jQuery Search Demonstration</title>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
    <script type="text/javascript">
    $(document).ready(function(){
        $(".keywords").keyup(function(){
            getData();
        });
        $(".table").click(function(){
            getData();
        });
    });
    
    function getData(){
        $.post("search.php", 
            {
                keywords: $(".keywords").val(),
                table: $('.table:checked').val()
            }, 
            function(data){
                $("div#content").empty();
                var phppage;
                switch($('.table:checked').val())
                {
                    case 'professor': 
                        phppage = 'prof';
                        break;
                    case 'department': 
                        phppage = 'department';
                        break;
                    case 'course': 
                        phppage = 'course';
                        break;
                } 
    
                $.each(data, function(){
                    $("div#content").append("- <a href='" + phppage + ".php?pID=" + this.id + "'>" + this.name + "</a>");
                });
            },
            "json");
    }
    </script>
    </head>
    <body>
    Search by:
    <input type="text" name="search" class="keywords" /><br />
    
    <input type="radio" name="table" class="table" value="professor" checked="checked" /> Professor<br />
    <input type="radio" name="table" class="table" value="department" /> Department<br />
    <input type="radio" name="table" class="table" value="course" /> Course<br />
    
    <div id="content"></div>
    
    </body>
    </html>
    

    PHP code:

    <?php
    $link = mysql_connect('localhost',"#","#");
    mysql_select_db("#", $link);
    
    $arr = array();
    $keywords = mysql_real_escape_string( $_POST["keywords"] );
    switch ($_POST["table"])
    {
        case 'professor';
            $arr = getProfessor($keywords);
            break;
        case 'department';
            $arr = getDepartment($keywords);
            break;
        case 'course';
            $arr = getCourse($keywords);
            break;
    }
    
    echo json_encode( $arr );
    
    function getProfessor($keywords){
        $arr = array();
    
        $query = mysql_query("SELECT pID, lname, fname 
                                FROM Professor 
                                WHERE CONCAT(lname,fname) LIKE '%". $keywords . "%'");
    
        while( $row = mysql_fetch_array ( $query ) )
        {
            $arr[] = array( "id" => $row["pID"], "name" => $row["fname"] . ' ' . $row["lname"]);
        }
    
        return $arr;
    }
    
    function getDepartment($keywords){
        $arr = array();
    
        $query = mysql_query("SELECT prefix, code 
                                FROM Department 
                                WHERE name LIKE '%". $keywords . "%'");
    
        while( $row = mysql_fetch_array ( $query ) )
        {
            $arr[] = array( "id" => $row["code"], "name" =>  $row["code"]);
        }
    
        return $arr;
    }
    
    function getCourse($keywords){
        $arr = array();
    
        $query = mysql_query("SELECT prefix, code 
                                FROM Course 
                                WHERE CONCAT(prefix,course) LIKE '%". $keywords . "%'");
    
        while( $row = mysql_fetch_array ( $query ) )
        {
            $arr[] = array( "id" => $row["code"], "name" => $row["code"]);
        }
    
        return $arr;
    }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Update: This turned into a blog post, with updated links and code, over at
Here's some code I saw once. Can you see what's wrong with it? [updated]
I have this function in my Javascript Code that updates html fields with their
I typically run a script each night that updates my code from SVN, then
Looking through some code I came across the following code trTuDocPackTypdBd.update(TrTuDocPackTypeDto.class.cast(packDto)); and I'd like
I wrote a batch script which recursively updates my source code against the company's
Update: Solved, with code I got it working, see my answer below for the
I have code in an Update Panel and even though on a button click
Replaces Question: Update multiple rows into SQL table Here's a Code Snippet to update
I've been asked to implement some code that will update a row in a

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.