Showing posts with label Reporting Tool in PHP. Show all posts
Showing posts with label Reporting Tool in PHP. Show all posts

Monday, September 26, 2011

PHP explode function on array

Today while working on the project of PHP-Reportica , I felt need of  applying php explode function on some php variable. Though usage of explode function was bit easy and I already used it, but this time I need to use it in much complicated way.

I was having a field with value of  selected_table_name.select_field_name. Now I had easily separated these two using function as:-

$explode_data= explode(".",  $tab_field);

Two arrays are formed now viz.  $explode_data[0] and $explode_data[1]. But issue was that first array might have redundant entries of same table names. Now, I stuck at this point, How to do it???

I find solution after about one hour spending one this thing. I came to know about a PHP function called unique array which removes redundant entries from an array.  Here below is what I needed:-
 foreach ($_POST['selfield'] as $mystring) {
$rs=explode(",",$mystring);
$first[]= $rs[0];
}
$uniqtab= array_unique($first);
$count= count($uniqtab);
$i=0;
foreach ($uniqtab as $table){
    echo $table;
     if ($i < ($count - 1)) {
      echo ', ';
   }
   $i=$i+1;
}

Wednesday, September 21, 2011

Field Listing Section of First Part of Reporting Tool

The day quite went tough as I had to struggle a lot while outputting the Field list on each selection of table via AJAX in Reporting Tool Project. But as is said, "All Well that Ends Well". Same happened with me. After doing so much struggle, I was able to resolve the issues.

Continuing to the previous Post's code,

If user selects the table, (I am showing a code snippet)

index.php
<h2><span>Please Select the </span>Credentials</h2><br/>
<form>
<label>Select The Table</label>
<?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';");
echo '<select name="table" onchange="return showfield(this.value);">';
while($result=pg_fetch_array($query)){
echo'<option value="'.$result['table_name'].'">'.$result['table_name'].'</option>';
}
}
echo '</select>';
?>
</form>

After that is shown

ajax.js
function showfield(str)
{
var xmlhttp;
if (str=="")
{
document.getElementById("result").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("result").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","showfield.php?table="+str,true);
xmlhttp.send();
}

This above ajax.js script which is issuing an ajax call for every selection of new table from the list.

and after that is

showfield.php
<?php
include_once 'config.php';
$t=$t.$_GET['table'];
$query= pg_query("SELECT column_name FROM information_schema.columns WHERE table_name ='$t';");
echo '<table border=1>';
echo '<tr><th colspan="5">Select Field</th></tr><tr>';
$i=1;
while($result=pg_fetch_array($query)){
echo '<td><input type="checkbox" name="field[]" value="'.$result['column_name'].'"/>'.$result[column_name].'</td>';
$i=$i+1;
if($i>5){
echo '</tr><tr>';
$i=1;
}
}
echo '</tr><tr><td colspan="5"><input type="submit" value="Enter fields" onclick="enterfield();" /></td>';
echo '<td colspan="5"><input type="submit" value="Clear Selected Fields" onclick="clear();" /></td></tr>';
echo '</table>';
?>

Which will List the all fields for a table. On the Selection of which and after submission will added to another table and user will again allowed to check whether they are sure to opt for all these fields. So Next Task after this will be Selection of Fields and Confirmation and Submission for Query Generation.

Monday, September 19, 2011

Selection of Formatting Logic

Logic Behind Generating is query is clearly visible in my mind, but I was stuck with the thing that how I am going to display the O/P in which format and that too importanly how???  So Brainstorming begins and along with that searching too, so as to collect some information about Formatting of Reports. But I did not work. so Whole Day went in thinking about the formatting. Hope fully tomorrow I will get the solution

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>';
?>

Thursday, September 15, 2011

Reporting Tool for PHP

Today I am over to my 3rd project that is the Reporting tool for PHP. As far as DIO Sir searched and also I searched we had not found any suitable tool for PHP to generate automatic reports on the basis of queries that are being generated. Those We found are not FOSS and which are FOSS were not living upto our expectations.

So An anlaysis started today regarding Generation of PHP Reporting Tool.

I divided it into 3 sections as per as following:-

  1. Dynamic Query Generation

  2. Display Formatted Report (preferably in Doc) on the basis of user selection of Fields formatting

  3. Final PHP code generated which is report code and can be integrated with the project


So I will work on these phases one by one. And Regarding the Feasibility of this Project, This Project is quite feasible but being feasible it is quite time consuming. Because I need to work a lot on the formatting of reports.