<?php

    //Connect to mysql server
    $link = mysqli_connect("localhost", "root", "R3M0T31") or die(mysqli_error());
    if(!$link) {
           die('Failed to connect to server: ' . mysqli_error());
    }
    //Select database
    $db = mysqli_select_db($link, "cropmonitor");
    if(!$db) {
           die("Unable to select database");
    }
    $query = "SHOW TABLES;";
    $result_tables = mysqli_query($link, $query);
?>

<!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" />
    <link rel="shortcut icon" href="https://raw.githubusercontent.com/josephworks/Table-Viewer/master/assets/images/favicon.ico" >
    <title>Table Viewer</title>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
    <script type="text/javascript" src="jquery.paginate.js"></script>
    <script type="text/javascript" src="tableupdater.js"></script>
    <link rel="stylesheet" type="text/css" href="style.css" media="screen">
    <link rel="stylesheet" type="text/css" href="chosen.css" media="screen">
    <link href='http://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,400italic&subset=latin,latin-ext' rel='stylesheet' type='text/css'>
</head>
<body>
<div id=wrapper>
    <h1>Databases</h1>
    <div id="formcontroles">
		<div class="tablecontrols">
			<select data-placeholder="Select table…" class="chzn-select" id="select-table" onchange="changetable()">
				<option value=""></option> 
        		<?php
        			while ($row = mysqli_fetch_array($result_tables)){
            			echo "<option>".$row[0]."</option>";
        			}
        		?>
			</select>
        </div>
        <div class="tablecontrols">
        	<select id="num-rows" onchange="changetable()" class="chzn-select" tabindex="2">
        		<option>10 Rows</option>
        		<option>20 Rows</option>
        		<option>30 Rows</option>
        		<option>50 Rows</option>
        		<option>100 Rows</option>
        	</select>
        </div>
	</div>
    <div id="table-show"></div>
    <div id="pagination"></div>
</div>
<script src="chosen.jquery.min.js" type="text/javascript"></script>
<script type="text/javascript"> $(".chzn-select").chosen(); $(".chzn-select-deselect").chosen({allow_single_deselect:true}); </script>
</body>
</html>