<?php 
include('header.php');
include('config.php');
if(isset($_GET['id'])) {
	$id = $_GET['id'];
	$query = "delete from `tbllenders` where `id`='".$id."';";
	$result = mysql_query($query);
	if($result)
	{
		echo "<script language='javascript'>alert('Delete successfully')</script>";
		echo "<script>window.location='lenders.php';</script>";
	}
	else
	{
		echo "<script language='javascript'>alert('Record has not been deleted.')</script>";
		echo "<script>window.location='lenders.php';</script>";
	}
}
?>
	<br />
	<div class="InnerContainer" >
    <h1>List Of Lenders</h1>
    <div class="Border"></div>
	<div class="AddNew"><a href="add.php">Add New</a></div>
	<table align='center' width="100%" style="text-align:center;">
		<tr>
			<th>Name</th>
			<th>Upfront Commission</th>
			<th>Trail Year 1</th>
			<th>Trail Year 2</th>
			<th>Trail Year 3</th>
			<th>Trail Year 4</th>
			<th>Trail Year 5~</th>
			<th>Edit</th>
			<th>Delete</th>
		</tr>
	<?php
		$query = "Select * from `tbllenders`  order by lender_name;";
		$result = mysql_query($query);
		$rows = mysql_num_rows($result);
		$tr=0;
		if ($rows > '0') 
		{		
			while($row=mysql_fetch_array($result))
			{
			if($tr==0)
			{
				echo "<tr class='ListColor'>";
				$tr=1;
			}
			else if($tr==1)
			{
				echo "<tr>";
				$tr=0;
			}
	?>
			<td align='left'><?php echo $row['lender_name']; ?></td>
		    <td><?php echo $row['front']; ?></td>
		    <td><?php echo $row['trail1']; ?></td>
		    <td><?php echo $row['trail2']; ?></td>
		    <td><?php echo $row['trail3']; ?></td>
		    <td><?php echo $row['trail4']; ?></td>
		    <td><?php echo $row['trail5']; ?></td>
			<td><a href="edit.php?id=<?php echo $row['id']; ?>"><img src="images/edit.png" /><a></td>
			<td><a href="lenders.php?id=<?php echo $row['id']; ?>" onclick="return confirm('Are you sure, you want to Delete?');"><img src="images/delete.gif" /></a></td>
		</tr>
	<?php	
			}
		}
		else
		{
			echo "<tr><td colspan='5' align='center'> No Result Found.</td></tr>";
		}
	?>
	</table>
	</div>
	</body>
</html>