基于基于行单击的php echo行获取值

时间:2018-05-17 08:26:20

标签: javascript php jquery

如何根据此编码中的行单击获取值?请帮帮我....

function addRowHandlers() {
  var tbody = $("#employee-click"); //document.getElementById("employee- 
  click ");
  tbody.each(function() {
    $(this).on('click', function() {
      var url = new URL(window.location.href);
      var no = url.searchParams.get("no");

      window.location.href = "detail.php?no=" + no;

    })
  })
}



<body  onload="addRowHandlers()">
	
	
 
		<div class="header"><h1>Data Biodata</h1></div>
		<div class="container" >
           <!-- <center> <button style="right:150"> <a href="Biodata.php">Create New</a></button></center>-->
			<table id="employee-grid" class="display" cellpadding="5" cellspacing="1"
			width="100%" border="1" style="text-align: justify;">
				<thead>
					<tr>
						<th>NO</th>
						<th>SVC NO</th>
						<th>RANK</th>
						<th>NAME</th>
						<th>YEAR</th>
						<th>SYSTEM</th>
						<th>COURSE</th>
						<th>F</th>
						<th>1</th>
						<th>2</th>
						<th>3</th>
						<th>4</th>
						<th>5</th>
						<th>6</th>
						<th>7</th>
						<th>8</th>
						<th>9</th>
						<th>10</th>
						
					</tr>
				</thead>
				
				<thead>
					<tr>
						<td><input type="text" id="0" class="employee-search-input"></td>
						
						<td><input type="text" id="1" class="employee-search-input"></td>
						<td><input type="text" id="2" class="employee-search-input" ></td>
						<td><input type="text" id="3" class="employee-search-input" ></td>
						<td><input type="text" id="4" class="employee-search-input" ></td>
						<td><input type="text" id="5" class="employee-search-input" ></td>
						<td><input type="text" id="6" class="employee-search-input" ></td>
						<td><input type="text" id="7" class="employee-search-input" ></td>
						<td><input type="text" id="8" class="employee-search-input" ></td>
						<td><input type="text" id="9" class="employee-search-input" ></td>
						<td><input type="text" id="10" class="employee-search-input" ></td>
						<td><input type="text" id="11" class="employee-search-input" ></td>
						<td><input type="text" id="12" class="employee-search-input" ></td>
						<td><input type="text" id="13" class="employee-search-input" ></td>
						<td><input type="text" id="14" class="employee-search-input" ></td>
						<td><input type="text" id="15" class="employee-search-input" ></td>
						<td><input type="text" id="16" class="employee-search-input" ></td>
						<td><input type="text" id="17" class="employee-search-input" ></td>
						</tr>
				</thead>
				<tbody id="employee-click">
					<tr>
                        <th>NO</th>
						<th>SVC NO</th>
						<th>RANK</th>
						<th>NAME</th>
						<th>YEAR</th>
						<th>SYSTEM</th>
						<th>COURSE</th>
						<th>F</th>
						<th>1</th>
						<th>2</th>
						<th>3</th>
						<th>4</th>
						<th>5</th>
						<th>6</th>
						<th>7</th>
						<th>8</th>
						<th>9</th>
						<th>10</th>
						
                       
					</tr>
    </tbody>
			</table>
		</div>
		
	</body>
&#13;
&#13;
&#13;

&#13;
&#13;
	$(document).ready(function() {
				
				
			var dataTable =  $('#employee-grid').DataTable( {
				processing: true,
				serverSide: true,
				ajax: "dataBiodata.php", // json datasource
				 
			
				} );

             
           
          


					
				$("#employee-grid_filter").css("display","none");  // hiding global search box
				
				$('.employee-search-input').on( 'keyup click change', function () {   
					var i =$(this).attr('id');  // getting column index
					var v =$(this).val();  // getting search input value
					dataTable.columns(i).search(v).draw();
				} );
			} );
			
    function addRowHandlers() {
    var tbody = $("#employee-click"); //document.getElementById("employee-click");
    tbody.each(function() {
    $(this).on('click', function() {     
    var url =new URL (window.location.href);
     var no = url.searchParams.get("no");
	  //window.location.href ="detail.php?no="+no;
	   alert(no);
	 		
    })
  })
}
&#13;
<body  onload="addRowHandlers()">
	
	
 
		<div class="header"><h1>Data Biodata</h1></div>
		<div class="container" >
           <!-- <center> <button style="right:150"> <a href="Biodata.php">Create New</a></button></center>-->
			<table id="employee-grid" class="display" cellpadding="5" cellspacing="1"
			width="100%" border="1" style="text-align: justify;">
				<thead>
					<tr>
						<th>NO</th>
						<th>SVC NO</th>
						<th>RANK</th>
						<th>NAME</th>
						<th>YEAR</th>
						<th>SYSTEM</th>
						<th>COURSE</th>
						<th>F</th>
						<th>1</th>
						<th>2</th>
						<th>3</th>
						<th>4</th>
						<th>5</th>
						<th>6</th>
						<th>7</th>
						<th>8</th>
						<th>9</th>
						<th>10</th>
						
					</tr>
				</thead>
				
				<thead>
					<tr>
						<td><input type="text" id="0" class="employee-search-input"></td>
						
						<td><input type="text" id="1" class="employee-search-input"></td>
						<td><input type="text" id="2" class="employee-search-input" ></td>
						<td><input type="text" id="3" class="employee-search-input" ></td>
						<td><input type="text" id="4" class="employee-search-input" ></td>
						<td><input type="text" id="5" class="employee-search-input" ></td>
						<td><input type="text" id="6" class="employee-search-input" ></td>
						<td><input type="text" id="7" class="employee-search-input" ></td>
						<td><input type="text" id="8" class="employee-search-input" ></td>
						<td><input type="text" id="9" class="employee-search-input" ></td>
						<td><input type="text" id="10" class="employee-search-input" ></td>
						<td><input type="text" id="11" class="employee-search-input" ></td>
						<td><input type="text" id="12" class="employee-search-input" ></td>
						<td><input type="text" id="13" class="employee-search-input" ></td>
						<td><input type="text" id="14" class="employee-search-input" ></td>
						<td><input type="text" id="15" class="employee-search-input" ></td>
						<td><input type="text" id="16" class="employee-search-input" ></td>
						<td><input type="text" id="17" class="employee-search-input" ></td>
						</tr>
				</thead>
				<tbody id="employee-click">
					<tr>
                        <th>NO</th>
						<th>SVC NO</th>
						<th>RANK</th>
						<th>NAME</th>
						<th>YEAR</th>
						<th>SYSTEM</th>
						<th>COURSE</th>
						<th>F</th>
						<th>1</th>
						<th>2</th>
						<th>3</th>
						<th>4</th>
						<th>5</th>
						<th>6</th>
						<th>7</th>
						<th>8</th>
						<th>9</th>
						<th>10</th>
						
                       
					</tr>
    </tbody>
			</table>
		</div>
		
	</body>
</html>







<?php
/* Database connection start */
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "testdb";

$conn = mysqli_connect($servername, $username, $password, $dbname) or die("Connection failed: " . mysqli_connect_error());

/* Database connection end */


// storing  request (ie, get/post) global array to a variable  
$requestData= $_REQUEST;

$columns = array( 
// datatable column index  => database column name
	0 => 'no', 
	1 => 'svcno',
	2 => 'pangkat',
	3 => 'name',
	4=> 'year',
	5 => 'system',
	6 => 'course',
	7 => 'f1',
	8 => 'f2',
	9=> 'f3',
	10 => 'f3',
	11 => 'f4',
	12 => 'f5',
	13 => 'f6',
	14 => 'f7',
	15 => 'f8',
	16 => 'f9',
	17 => 'f10',
	18 => 'f11',
);



// getting total number records without any search
$sql = "SELECT no";
$sql.=" FROM av";
$query=mysqli_query($conn, $sql) or die("dataBiodata.php: get biodata");
$totalData = mysqli_num_rows($query);
$totalFiltered = $totalData;  // when there is no search parameter then total number rows = total number filtered rows.


$sql = "SELECT no,svcno,pangkat,name,year,system,course,f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11";
$sql.=" FROM av WHERE 1=1";
if( !empty($requestData['columns'][0]['search']['value']) ){
	$sql.=" AND  no LIKE '".$requestData['columns'][0]['search']['value']."%' ";    
}
if( !empty($requestData['columns'][1]['search']['value']) ){
	$sql.=" AND  svcno LIKE '".$requestData['columns'][1]['search']['value']."%' ";
}
if( !empty($requestData['columns'][2]['search']['value']) ){
	$sql.=" AND  pangkat LIKE '".$requestData['columns'][2]['search']['value']."%' ";
}
if( !empty($requestData['columns'][3]['search']['value']) ){
	$sql.=" AND  name LIKE '".$requestData['columns'][3]['search']['value']."%' ";
}
if( !empty($requestData['columns'][4]['search']['value']) ){
	$sql.=" AND  year LIKE '".$requestData['columns'][4]['search']['value']."%' ";
}
if( !empty($requestData['columns'][5]['search']['value']) ){
	$sql.=" AND  system LIKE '".$requestData['columns'][5]['search']['value']."%' ";
}
if( !empty($requestData['columns'][6]['search']['value']) ){
	$sql.=" AND  course LIKE '".$requestData['columns'][6]['search']['value']."%' ";
}
if( !empty($requestData['columns'][7]['search']['value']) ){
	$sql.=" AND  f1 LIKE '".$requestData['columns'][7]['search']['value']."%' ";
}
if( !empty($requestData['columns'][8]['search']['value']) ){
	$sql.=" AND  f2 LIKE '".$requestData['columns'][8]['search']['value']."%' ";
}



$query=mysqli_query($conn, $sql) or die("dataBiodata.php: get biodata");
$totalFiltered = mysqli_num_rows($query); // when there is a search parameter then we have to modify total number filtered rows as per search result. 
$sql.=" ORDER BY ". $columns[$requestData['order'][0]['column']]."   ".$requestData['order'][0]['dir']."  LIMIT ".$requestData['start']." ,".$requestData['length']."   ";
/* $requestData['order'][0]['column'] contains column index, $requestData['order'][0]['dir'] contains order such as asc/desc  */	
$query=mysqli_query($conn, $sql) or die("dataBiodata.php: get biodata1");
	

$data = array();
while( $row=mysqli_fetch_array($query) ) {  // preparing an array
	$nestedData=array(); 
	$nestedData[] = $row["no"];
	$nestedData[] = $row["svcno"];
	$nestedData[] = $row["pangkat"];
	$nestedData[] = $row["name"];
	$nestedData[] = $row["year"];
	$nestedData[] = $row["system"];
	$nestedData[] = $row["course"];
	$nestedData[] = $row["f1"];
	$nestedData[] = $row["f2"];
    $nestedData[] = $row["f3"];
    $nestedData[] = $row["f4"];
    $nestedData[] = $row["f5"];
    $nestedData[] = $row["f6"];
    $nestedData[] = $row["f7"];
    $nestedData[] = $row["f8"];
    $nestedData[] = $row["f9"];
    $nestedData[] = $row["f10"];
    $nestedData[] = $row["f11"];

	$data[] = $nestedData;
	

}



$json_data = array(
			"draw"            => intval( $requestData['draw'] ),   // for every request/draw by clientside , they send a number as a parameter, when they recieve a response/data they first check the draw number, so we are sending same number in draw. 
			"recordsTotal"    => intval( $totalData ),  // total number of records
			"recordsFiltered" => intval( $totalFiltered ), // total number of records after searching, if there is no searching then totalFiltered = totalData
			"data"            => $data   // total data array
			);

echo json_encode($json_data);  // send data as json format


?>
&#13;
&#13;
&#13; 这是完整的代码。任何人都知道怎么做,请不要犹豫与我分享。

0 个答案:

没有答案