<?php
require('../config/dbcon.php');
$output = '';
if (isset($_POST["query"])) {

	$query = "SELECT noofrow FROM noofrow_mst WHERE description='noofrow'";
	$rs = mysqli_query($connect, $query) or die("Cannot execute query: $query\n");
	while ($row = mysqli_fetch_assoc($rs)) {
		$noofrow     = $row['noofrow'];
	}

	$search = mysqli_escape_string($connect, $_POST["query"]);
	$query = "SELECT * FROM disc_mst WHERE Lower(customer_name) LIKE Lower('%" . $search . "%') or Lower(customer_code) LIKE Lower('%" . $search . "%') or Lower(cust_place) LIKE Lower('%" . $search . "%') or Lower(segment) LIKE Lower('%" . $search . "%') limit $noofrow";
} else {

	$query = "SELECT noofrow FROM noofrow_mst WHERE description='noofrow'";
	$rs = mysqli_query($connect, $query) or die("Cannot execute query: $query\n");
	while ($row = mysqli_fetch_assoc($rs)) {
		$noofrow     = $row['noofrow'];
	}

	$query = "SELECT * FROM disc_mst ORDER BY customer_name limit $noofrow";
}

$result = mysqli_query($connect, $query);
if (mysqli_num_rows($result) > 0) {
	$output .= '
	<div class="table-responsive" style="width: 95%; margin-left : 2.5%; height: 380px;">
		<table id="tblexportData" class="table table bordered" >
			<tr>
				<th width="30px" style=" text-align: center">Edit</th>
				<th style = "width:400px; text-align: left">id</th>
				<th style = "width:50px; text-align: left">customer_code</th>
				<th style = "width:400px; text-align: left">customer_name</th>
				<th style = "width:200px; text-align: left">cust_place</th>
				<th style = "width:200px; text-align: left">segment</th>
				<th style = "width:200px; text-align: left">disc_per</th>
			</tr>';
	while ($row = mysqli_fetch_array($result)) {
		$output .= '
			<tr>
				<td style="text-align: center"><button type="button" style="width:60px; height:25px;" name="update" id="' . $row["id"] . '" class="update btn btn-success btn-xs">Edit</button></td>  
				<td style="text-align: left">' . $row["id"] . '</td>
				<td style="text-align: left">' . $row["customer_code"] . '</td>
				<td style="text-align: left">' . $row["customer_name"] . '</td>
				<td style="text-align: left">' . $row["cust_place"] . '</td>
				<td style="text-align: left">' . $row["segment"] . '</td>
				<td style="text-align: left">' . $row["disc_per"] . '</td>
			</tr>
		';
	}
	echo $output;
} else {
	echo 'Data Not Found';
}
?>
<script>
/*
	var table = document.getElementById('tblexportData');                
    for(var i = 1; i < table.rows.length; i++)
    {
        table.rows[i].onclick = function()
        {
			document.getElementById("disc_srno").value = this.cells[1].innerHTML;
			document.getElementById("customer_code").value = this.cells[2].innerHTML;
			document.getElementById("customer_name").value = this.cells[3].innerHTML;
			document.getElementById("cust_place").value = this.cells[4].innerHTML;
			document.getElementById("segment").value = this.cells[5].innerHTML;
			document.getElementById("disc_per").value = this.cells[6].innerHTML;
			//document.getElementById("new").value = 2;
			document.getElementById("disc_per").focus();
		};
    }
	*/
</script>