<?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 pdisc_mst WHERE Lower(supplier_name) LIKE Lower('%" . $search . "%') or Lower(supplier_code) LIKE Lower('%" . $search . "%') or Lower(supplier_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 pdisc_mst ORDER BY supplier_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">supplier_code</th>
				<th style = "width:400px; text-align: left">supplier_name</th>
				<th style = "width:200px; text-align: left">supplier_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;" 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["supplier_code"] . '</td>
				<td style="text-align: left">' . $row["supplier_name"] . '</td>
				<td style="text-align: left">' . $row["supplier_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';
}
?>