Friday, September 16, 2011

Table Listing in Reporting tool Project

So, Today I started first with preparing Front End page for Selecting out which Tables of  database you want to work on. While Selecting a table you will be prompted to select the Fields, from which you have to select the fields for your query.  Ok Leave it this          is the next part of phase 1.

Below is the code discussed which is front end and will show you the each and every table of selected database:-

index.php
<html lang="en">
<head>
<script class="jsbin" src="jquery.min.js"></script>
<meta charset="utf-8" />
<link href="tablecloth/tablecloth.css" rel="stylesheet" type="text/css" media="screen" />
<script type="text/javascript" src="tablecloth/tablecloth.js"></script>
<script type="text/javascript" src="myscript.js"></script>
<script type="text/javascript">
var t = new ScrollableTable(document.getElementById('myScrollTable'), 150,250);
</script>

<title></title>
<script>
function showfield()// jQuery Function
{
var name = $("input[name='table']:checked").val();
jQuery.ajax({
url:'showfield.php',
type:"POST",
data: { clientdata : name },
success:function(data){ document.getElementById("result").innerHTML= data;}
});
return false;
}
</script>
<script>
function enterfield()// jQuery Function
{
var Selected = new Array();
jQuery("input[name='field[]']:checked").each(function(){
Selected.push(jQuery(this).val());
});

jQuery.ajax({
url:'enterfield.php',
type:"POST",
data: { clientdata : Selected },
success:function(data){ document.getElementById("enterfield").innerHTML= data;}
});
return false;
}
</script>
</head>
<body>
<form>
<table style="margin-left: auto; margin-right: auto;" id="myScrollTable">
<tr>
<th>
Select Table
</th>
</tr>
<?php
include_once 'config.php';
if($op=='mysql'){

}
elseif ($op=='postgresql') {
$query=pg_query("SELECT table_name FROM information_schema.tables WHERE table_schema = 'public';");
/*Above Query retrieve table names from selected database in config.php */ 
while($result=pg_fetch_array($query)){
echo'<tr><td>';
echo'<input type="radio" name="table" value="'.$result['table_name'].'"onclick="showfield();" />'.$result['table_name'].'</td>';
echo '</tr>';
}
}
?>
</table>
</form>
<div id="result">

</div>
<div id="enterfield">

</div>
<p><tt id="results"></tt></p>
</body>
</html>

After That is the showfield.php from which fields for table are displayed for every click on radio button of table
showfield.php
<?php
include_once 'config.php';
$t= $_POST['clientdata'];
$query= pg_query("SELECT column_name FROM information_schema.columns WHERE table_name ='$t';");
echo '<table>';
echo '<tr><th>Select Field</th></tr>';
while($result=pg_fetch_array($query)){
echo '<tr><td><input type="checkbox" name="field[]" value="'.$result['column_name'].'" onclick="enterfield();"/>'.$result[column_name].'</td></tr>';
echo'</br>';
}
echo '</table>';
?>

No comments:

Post a Comment