0
<in search.php>


<?php require_once("../includes/session.php"); ?>
<?php require_once("../includes/connection.php") ?>
<?php require_once("../includes/functions.php") ?>
<?php

$searchq = $_POST['searchq'];
$tablehead="<tr><th>Product Name</th><th>Category</th><th>Price</th><th>Discount</th><th>Edit</th></tr>";
$tabledata = "";
if(empty($searchq)) {
    echo "";
    } else {
    //If there is text in the search field, this code is executed every time the input changes.
    echo "<div id='results'-->"; //this div is used to contain the results. Mostly used for styling.

    //This query searches the name field for whatever the input is.
    $sql = "SELECT * FROM `tblstudent` WHERE `student_id` LIKE '%$searchq%' or `name` LIKE '%$searchq%' or `email` LIKE '%$searchq%'";

    $result = mysql_query($sql);

    while($row = mysql_fetch_assoc($result)) {

       $id = $row['id'];
       $student_id=htmlentities($row['student_id']);

        $hashed_password=htmlentities($row['hashed_password']);
        $name=htmlentities($row['name']);
        $email=htmlentities($row['email']);

“这是我添加但不起作用的部分,没有错误”

$tabledata.="<tr id='$id' class='edit_tr'><td class='edit_td' >
    <span id='one_$id' class='text'>$student_id</span>
    <input type='text' value='$student_id' class='editbox' id='one_input_$id' />
    </td>

    <td class='edit_td' >
    <span id='two_$id' class='text'>$hashed_password</span> 
    <input type='text' value='$hashed_password' class='editbox' id='two_input_$id'/>
    </td>

    <td class='edit_td' >
    <span id='three_$id' class='text'>$name $</span> 
    <input type='text' value='$name' class='editbox' id='three_input_$id'/>
    </td>

    <td class='edit_td' >
    <span id='four_$id' class='text'>$email $</span> 
    <input type='text' value='$email' class='editbox' id='four_input_$id'/>
    </td>

    <td><a href='#' class='delete' id='$id'> X </a></td>

    </tr>";
    }
    $finaldata = "<table width='100%'>". $tablehead . $tabledata . "</table>"; // Content for Data

            }          
            echo "</div>";

    ?>

这是js查询插件。

<EditDeletePage.js>
$(document).ready(function()
{
$(".delete").live('click',function()
{
var id = $(this).attr('id');
var b=$(this).parent().parent();
var dataString = 'id='+ id;
if(confirm("Sure you want to delete this update? There is NO undo!"))
{
    $.ajax({
type: "POST",
url: "delete_ajax.php",
data: dataString,
cache: false,
success: function(e)
{
b.hide();
e.stopImmediatePropagation();
}
           });
    return false;
}
});


$(".edit_tr").live('click',function()
{
var ID=$(this).attr('id');

$("#one_"+ID).hide();
$("#two_"+ID).hide();
$("#three_"+ID).hide();
$("#four_"+ID).hide();


$("#one_input_"+ID).show();
$("#two_input_"+ID).show();
$("#three_input_"+ID).show();
$("#four_input_"+ID).show();


}).live('change',function(e)
{
var ID=$(this).attr('id');

var one_val=$("#one_input_"+ID).val();
var two_val=$("#two_input_"+ID).val();
var three_val=$("#three_input_"+ID).val();
var four_val=$("#four_input_"+ID).val();

var dataString = 'id='+ ID +'&name='+one_val+'&category='+two_val+'&price='+three_val+'&discount='+four_val;
if(one_val.length>0&& two_val.length>0 && three_val.length>0 && four_val.length>0)
{

$.ajax({
type: "POST",
url: "live_edit_ajax.php",
data: dataString,
cache: false,
success: function(e)
{

$("#one_"+ID).html(one_val);
$("#two_"+ID).html(two_val);
$("#three_"+ID).html(three_val);
$("#four_"+ID).html(four_val);

e.stopImmediatePropagation();

}
});
}
else
{
alert('Enter something.');
}

});

// Edit input box click action
$(".editbox").live("mouseup",function(e)
{
e.stopImmediatePropagation();
});

// Outside click action
$(document).mouseup(function()
{

$(".editbox").hide();
$(".text").show();
});


//Pagination            
function loading_show(){
$('#loading').html("<img src='images/loading.gif'/>").fadeIn('fast');
}
function loading_hide(){
$('#loading').fadeOut('fast');
}                
function loadData(page){
loading_show();                    
$.ajax
({
type: "POST",
url: "load_data.php",
data: "page="+page,
success: function(msg)
{
$("#container").ajaxComplete(function(event, request, settings)
{
loading_hide();
$("#container").html(msg);
});
}
});
}
loadData(1);  // For first time page load default results
$('#container .pagination li.active').live('click',function(){
var page = $(this).attr('p');
loadData(page);
});           
$('#go_btn').live('click',function(){
var page = parseInt($('.goto').val());
var no_of_pages = parseInt($('.total').attr('a'));
if(page != 0 && page <= no_of_pages){
loadData(page);
}else{
alert('Enter a PAGE between 1 and '+no_of_pages);
$('.goto').val("").focus();
return false;
}
});
});

我从http://palavas.biz/forum/viewtopic.php?f=51&t=4143&sid=9241f1f287fc672cc32f91a06b93f4c3#.UjqVx9Jmim4编辑但不起作用...我尝试将已经有表格显示的功能更改为搜索功能只显示出来。但不幸的是,当在搜索关键字文本框中键入单词时,我无法显示表内列出的数据。

4

0 回答 0