Ibshas25 Posted November 11, 2010 Share Posted November 11, 2010 <!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> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Search User</title> <link href="stylesheet1.css" rel="stylesheet" type="text/css"/> <script type="text/javascript" src="jquery-1.4.3.js"></script> <script type="text/javascript" src="jquery.json-2.2.js"></script> <style type="text/css"> body { font-size:12px; font-family:Arial, Helvetica, sans-serif; } form { display:block; width:260px; } form .input{ width:120px; float:right; } form label { display:block; width:260px; clear:both; } form textarea { display:block; width:260px; } </style> <script type="text/javascript"> // alert("document loaded 1"); $(document).ready(function(){ //$("#projectid").html("1"); // alert("document loaded 1"); function userlistgenerate(){ var data = { "operation" : "userlist", "teams": [ { "userid" : "usr_id"}, ] // end of sales array } //alert("geldi 2"); //var dataString = JSON.(data); var dataString = $.toJSON(data); //alert("geldi 3"); // alert(dataString); $.post('UserSearchPBT.php', { data: dataString}, userlistResult, "text"); $("#selectedUserName").html(""); // $("selectedUserName").hide("fast"); } function userlistResult(res) { //alert("checkResult"); // $("#userlist").html("Full response: " +res); var obj = $.evalJSON(res); //alert(obj.ResultData); //$("#sales1Lastname").html("Lastname of sales[1]: " +obj.sales[0].lastname); $("#userlist").html(obj.ResultData); $("#selectedUserName").html(""); //$("selectedUserName").hide("fast"); } function usersearch() { //alert(document.getElementById("name").value); //alert(document.getElementById("surname").value); var name=$("#name").attr("value"); var surname=$("#surname").attr("value"); // alert ("user search a geliyor"); //var formdata = 'name' : "'+document.getElementById("name").value+",'surname' : '"+document.getElementById("surname").value" ; var data = { "operation" : "usersearch", "user": [ { "name" : name, "surname" : surname } // { "name" : name+"xx", "surname" : surname+"xx" }, // { "name" : name+"yy", "surname" : surname+"yy" } ] // end of sales array } // alert("geldi 1"); //var dataString = JSON.(data); var dataString = $.toJSON(data); // alert(dataString); //alert("geldi 3"); // alert(dataString); $.post('UserSearchPBT.php', { data: dataString}, usersearchResult, "text"); } function usersearchResult(res) { //alert("checkResult"); // $("#userlist").html("Full response: " +res); var obj = $.evalJSON(res); //alert(obj.ResultData); //$("#sales1Lastname").html("Lastname of sales[1]: " +obj.sales[0].lastname); $("#userlist").html(obj.ResultData); } function UserSearchChoose(userId,userName,userSurName){ //alert(userSurName) $("#userid").val(userId); $("#selectedUserName").html(userName+" "+userSurName); //$("selectedUserName").show("fast"); //$("#selectedUserName").val(userName+" "+userSurName); //$("div").hide(2000); //$("#selectedUserName").show("slow"); } </script> </head> <body> <form id="iletisim"> <div id="formdiv"> <table><tr> <td><span id="successfailmessage"></span></td> <tr><td><span id="userlist"></span> </td></tr> <td> <!-- <a href='#' onclick="javascript:teamsearch();">Team Search</a> --> <a href='#' onclick="javascript:userdelete();">Delete User</a> </td> <tr><td> </td></tr> <tr><td><span id="selectedUserName"></span></td></tr> <tr><td><label for="name">Name<input class="input" name="name" id="name" type="text" value="" /></label></td></tr> <tr><td><label for="surname">Surname<input class="input" name="surname" id="surname" type="text" value="" /></label><tr> <tr><td><a href='#' onclick="javascript:usersearch();">Search User</a> </td></tr> <tr><td><span id="userlist"></span> </td></tr> </table></td></tr> </tr> </div> </form> </body> </html> ?php include("JSON.php"); require_once("connectdb.php"); $req = json_decode(stripslashes($_POST['data']), true); $req["SuccFail"]="fail"; $req["SuccFailMessage"]="Error Occured."; //$logFile = 'logFile'; // error_log("isl=baþladý: ", 3, $logFile); if ($req['operation'] == "usersearch") // select için veri geldi { // error_log("isl==select oluþuyor: ", 3, $logFile); $sql= "select usr_id, usr_username,usr_name,usr_surname,usr_isuseractive from users"; $sql.=" where (usr_name is null or usr_name like '". $req['user'][0]['name']."%' ) and "; $sql.= "(usr_surname is null or usr_surname like '". $req['user'][0]['surname']."%' ) "; $sql .= " order by usr_name , usr_surname"; //error_log($sql, 3, $logFile); //error_log("sql: ".$sql, 3, $logFile); //error_log("\n", 3, $logFile); $result = mysql_query($sql); $reslist = "<table border='1'><tr><th>User Id</th><th>Username</th><th>Name</th><th>Surname</th><th>Is Active</th></tr>"; while($row = mysql_fetch_array($result)) { // error_log("user: ".$row['usr_name']." surname :".$row['usr_username'], 3, $logFile); $user = $row['usr_name']." ".$row['usr_surname']; $reslist .= "<tr><td><a href='#' onclick='javascript:UserSearchChoose(".$row['usr_id'].",".chr(34).$row['usr_name'].chr(34).",".chr(34).$row['usr_surname'].chr(34).");'>".$row['usr_id']."</a></td><td>" . $row['usr_username']chr(34) . "</td><td>" . $row['usr_name'] . "</td>"; $reslist .= "<td>" . $row['usr_surname'] . "</td><td>" . $row['usr_isuseractive'] . "</td></tr>"; } // error_log("$reslist: ".$reslist, 3, $logFile); $reslist .= "</table>"; $req["SuccFail"]="success"; //operation success or fail $req["SuccFailMessage"]="successfully selected."; //alert($reslist); $req["ResultData"]=$reslist; mysql_close($conn); header("Content-type: text/plain"); echo json_encode($req); return; } else if ($req['operation'] == "userlist") // select için veri geldi { // error_log("isl==teamslist select oluþuyor: ", 3, $logFile); $sql="select usr.usr_name,usr.usr_surname where usr.usr_id =".$req['user'][0][usr_id]; $sql.=" order by usr.usr_name , usr.usr_surname "; $result = mysql_query($sql); $reslist = "<table border='1'><tr><th>Users Info</th> </tr>"; while($row = mysql_fetch_array($result)) { // error_log("user: ".$row['usr_name']." surname :".$row['usr_username'], 3, $logFile); //$user = $row['usr_name']." ".$row['usr_surname']; $reslist = "<tr><td><a href='#' onclick='javascript:usersearchChoose(".$row['usr_id'].",".$row['usr_username'].chr(34).",". $row['usr_name'].chr(34)",".$row['usr_surname'].chr(34).",".chr(34).$row['usr_email'].chr(34).",".chr(34).$row'usr_contact'].chr(34).");'> " . " ==> " . $row['usr_isuseractive'] . "</a></td></tr>"; } // error_log("$reslist: ".$reslist, 3, $logFile); $reslist .= "</table>"; $req["SuccFail"]="success"; //operation success or fail $req["SuccFailMessage"]="successfully selected."; //alert($reslist); $req["ResultData"]=$reslist; mysql_close($conn); header("Content-type: text/plain"); echo json_encode($req); return; } else if ($req['operation'] == "userdelete") // teams silmek için geldi. { //error_log("isl==teamdelete: ", 3, $logFile); //$sql="delete from teams where tea_id=".$req['teamid']; mysql_query("delete from users where usr_id=".$req['usr_id']); //error_log("mysql_affected_rows= ".mysql_affected_rows($con), 3, $logFile); //var $affrows = mysql_affected_rows(); if ( mysql_affected_rows() > 0 ) { $req["SuccFail"]="success"; //operation success or fail $req["SuccFailMessage"]="successfully deleted."; //error_log("isl==teamdelete:success ", 3, $logFile); } else { $req["SuccFail"]="fail"; //operation success or fail $req["SuccFailMessage"]="error occured ". mysql_error(); // error_log("isl==teamdelete:fail ", 3, $logFile); } mysql_close($conn); header("Content-type: text/plain"); echo json_encode($req); return; } Quote Link to comment https://forums.phpfreaks.com/topic/218380-trying-to-make-search-and-select-work-at-the-same-time/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.