<!DOCTYPE html>
	<title>N queen Problem solver</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>

	<script src="jquery.js"></script>
    <script src=jPaginate.js></script>
    <!-- bootstarap -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
    <link type="text/css" rel="stylesheet" href="style.css"  media="screen,projection"/>


<div class="container main">
<div class="row">
    <p style="margin: 0" class="pull-right"><a href="source.php" title="Source code" target="blank">view code ></a></p>
<div class="row">
	<div class="col s12">
		<h2>N queen solver</h2>

<div class="row">
	<form class="col-lg-12" method="post">
		<div class="input-group">
			<input type="text" name="number" class="form-control" placeholder="How many queens?" autofocus <?php  if (isset($_POST["number"])) echo "value='".$_POST["number"]."'";?> />
<!-- 			<label for="number">How many queens?</label> -->
			<span class="input-group-btn">
				<button class="btn btn-default" type="submit">Submit</button>
<div class="row">
	<div id="result">

if (!isset($_POST["number"])){
	die("Please enter a value");
	$board = [];
	$count = 0;

// check if it is safe to place the queen
function isSafe($row, $col){

	global $board;

    for($i=1; $i<$row; $i++){
    //checking column and digonal conflicts
	        return 0;
	    else if(abs($board[$i]-$col)==abs($i-$row))
	    	return 0;

    return 1; //no conflicts

function printboard($n){
	global $board, $count;
    echo "<h3>Solution $count:</h3>";
	echo "<table class='table'>";
    echo "<tr><th></th>";

    for($i=1; $i<=$n; ++$i)
        echo "<th>$i</th>";
    echo "</tr>";

    for($i=1; $i<=$n; ++$i){
        echo "<tr><td>$i</td>";

        for($j=1; $j<=$n;++$j){ //for nxn board
                echo "<td>Q</td>"; //queen at i,j position
                echo "<td>-</td>"; //empty slot
        echo "</tr>";

    echo "</table>";

function solveQ ($row, $n){
global $board;

    for($col=1; $col<=$n; ++$col){
        if(isSafe($row, $col)){
            $board[$row]=$col; //no conflicts so place queen
        if($row==$n){ //dead end
            printboard($n); //printing the board configuration
        else //try queen with next position

// execute

</div><!-- result -->
<h4><?php echo $count; ?> solutions found.</h4>

</div> <!-- row -->

</div><!-- container -->
<script type="text/javascript">

	$("#result").jPaginate({items: 2, active: "active", minimize: false, nav_items: 4, cookies: "false"});