Jump to content

Search support incident data is overwritten


phpVietHa

Recommended Posts

I have a questions like this. Now click on the button once I get search keywords entered data into it. Then I want is a new keyword search with the old data must be destroyed and new data show. Please do help me sir!

process with php :

bookModel

<?php
    require_once 'database.php';
    class Books
    {
        var $conn;
        public function __construct()
        {
            $this->conn = new Database();
        }
        // cac phuong thuc ghi o day
        public function getBookList()
        {
            $sql = "SELECT * FROM booklist order by bookid DESC";
            $result = mysql_query($sql);
            $data = array();
            while($rows = mysql_fetch_assoc($result))
            {
                $data[] = $rows;
            }
            return $data;
        }
        // viet function tim kiem thong tin voi keyword nhap vao
        public function searchBooks($keyword)
        {
            $sql = "SELECT * FROM booklist WHERE bookName like '%$keyword%' ORDER BY bookID desc";
            $result = mysql_query($sql);
            $data = array();
            while($rows = mysql_fetch_assoc($result))
            {
                $data[] = $rows;
            }
            return $data;
        }
    }
?>

process get data php

<?php
    require 'bookModel.php';
    $bookList = new Books();       
    $keyWord = $_POST['textSearch']; // tu khoa tim kiem nhap ben phia client
    // gio ta se tim kiem trong dong du lieu vua roi 
    $data = $bookList->searchBooks($keyWord);                    
    $jsonString = json_encode($data);
    print_r($jsonString);
?>

Search html

<!DOCTYPE HTML>
<html>
    <head>
        <script type="text/javascript" src="jquery-1.10.2.js"></script>
        <script type="text/javascript">
            $("document").ready(function(){
                var dem = 0; // chua click thi i = 0
                $("#Search").click(function(){
                    var url = "newWind.php";
                    var dta = {
                        "textSearch": $("#searchForm :text[name='txtSearch']").val()
                    };
                    $.post(url,dta,function(data,status)                                       
                    {
                        console.log(data);
                        console.log(status);
                        var html = "<table border='1'";
                        $.each(data,function(key,value){
                            html += "<tr>";
                                html += "<td>" +value["bookID"] +"</td>";
                                html += "<td>" +value["bookName"] +"</td>";                                
                                html += "<td>" +value["bookPrice"] +"</td>";
                            html += "</tr>"; 
                        });
                        html += "</table>";
                        $("#Result").append(html);                                            
                    },'json');
                    dem += 1; // tang i len 1
                    if(dem > 1)
                    {
                        $("#Result").remove();                        
                    }                    
                }); 
            });
        </script>
    </head>
    <body>
        <!-- thiet ke giao dien tim kiem -->
        <form action="" id="searchForm">
            <label>Input keyword:</label>
            <input type="text" name="txtSearch"/>
            <br />
            <input type="button" name="btnSearch" id="Search" value="Search"/>
        </form>
        <div id="Result">
                        
        </div>          
    </body>
</html>
 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.