Display php returned database records in another div

Display php returned database records in another div

Hello,

sorry am a newbie in JQuery.

I have three php files, one of the php file contains the selectable records, which i need after a selection the query fetches the data from the table and displays them in another php file. This process is working fine.

The problem i have is, i need to display such php returned records into the other div. When am doing this i can just display the php but no records are returned.

If i do it without div, the records are returned and display but NOT in the div.

You help please?

here is my code:

main.php
  This one when executed, it opens the correctly but NOT in the <div id="output" ...> </div>

===start of main.php=============

{This one contains the <div id="output" ..> /</div> where i wish to display the rpt_print_reports.php with returned records from the database.}

<?php
include('../../header.php');

?>

<script type="text/javascript" src="../../js/sadaka.js"></script>
<!--<script src=" http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> -->



<table style="padding:0">
<tr>

<td style="width:800px; padding:0; vertical-align:top">

<input id="search" type="text" placeholder="Type to search" onkeyUp="loadContent('grids', 'rpt_kandas_grid.php?keyword='+this.value+'&show='+showContent)"
style="width:360px; height:26px; padding-left:20px; font-size:16px; margin-bottom:10px; background-image:url('../../images/search.gif'); background-repeat:no-repeat" />
<!--
<input name="show" type="radio" value="all" id="show_all" checked="checked" onchange="sortPrintSadaka(this.value)" /><label for="show_all">All</label>
<input name="show" type="radio" value="printed" id="show_printed" onchange="sortPrintSadaka(this.value)" /><label for="show_printed">Printed</label>
<input name="show" type="radio" value="unprinted" id="show_unprinted" onchange="sortPrintSadaka(this.value)" /><label for="show_unprinted">Not printed</label>
-->
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;

<a onclick="$('#ajaxForm').submit()"> <img src="../../images/icons/check-black.png" class="icon" />Print selected</a>


<div style="width:390px; margin-top:10px" id="grids">

<?php include('rpt_kandas_grid.php');
 
?>

</div>

</td>

<td style="width:800px; vertical-align:top">

<div id="notification"></div>

<div id="content" class="container">
<div id="output" style="width:850px">
 

</div>
</div>

</td>




</tr>
</table>

<?php include('../../footer.php') ?>

=====end of main.php==============


==========start of rpt_kandas_grid===========
{This one displays a grid to allow for  user to make selection of the records to include in the report. (rpt_print_reports for printing.}

<?php
include('../../config.php');
include('../../labels/sadaka.php');
include('../../functions/common.php');
include('../../functions/sadaka.php');

if(isset($_REQUEST['keyword'])) {
    $keyword = $_REQUEST['keyword'];
} else {
    $keyword = '';
}

$row = 0;
if(isset($_REQUEST['page'])) {
    $current_page = $_REQUEST['page'];
} else {
    $current_page = 1;
}
$start_page = ($current_page - 1) * 10;





// die(print_r($_REQUEST));



if(isset($_REQUEST['show'])) {
    $show = $_REQUEST['show'];

   
    $pagenate_query = $connection->query("Select kandas.kanda_id,kandas.kandaname,Count(memberships.memberid) As idadi
                    From kandas Inner Join memberships On kandas.kanda_id = memberships.kanda_id
                    WHERE (`kandas`.`kanda_id` LIKE '%$keyword%' OR `kandas`.`kandaname` LIKE '%$keyword%')
                    Group By `kandas`.`kanda_id`
                    ORDER BY `kandas`.`kanda_id` ASC");

    pagenate($pagenate_query, 'rpt_kandas_grid.php');
}
?>

<script type="text/javascript" src="../../js/ajax_form.js"></script>

<form  id="ajaxForm" method="post" action="rpt_print_reports.php">

<table style="width:100%; border-radius:4px 4px 0 0">
<tr class="header table-header" style="height:30px">
<td style="width:20px">
<label for="check_all"> <?php //echo $lb_check_all; ?> </label>
<input type="checkbox" name="check_all" id="check_all" style="position:relative; top:0px; margin:0" onchange="checkAll(this.checked, 'check')" /> </td>
<td style="width:40px"> <?php echo $lb_rpt_kanda_id; ?> </td>
<td style="width:160px"> <?php echo $lb_rpt_kanda; ?> </td>
<td style="width:80px"> <?php echo $lb_rpt_idadi; ?> </td>
</tr>

<?php

//if (is_array($variable)) {
$fetch_query="Select kandas.kanda_id,kandas.kandaname,Count(memberships.memberid) As idadi
                    From kandas Inner Join memberships On kandas.kanda_id = memberships.kanda_id
                    WHERE (`kandas`.`kanda_id` LIKE '%$keyword%' OR `kandas`.`kandaname` LIKE '%$keyword%')
                    Group By `kandas`.`kanda_id`
                    ORDER BY `kandas`.`kanda_id` ASC";

           
    foreach ($connection->query($fetch_query) as $members) {
        $kanda_id = $members['kanda_id'];
        $kanda_name = $members['kandaname'];
        $idadi = $members['idadi'];
               
        //if($date_printed < '2000-00-00') $date_printed = '';

    echo '<tr id="row_'.$row.'"';
        if($row % 2) {echo 'class="odd"'; } else {echo 'class="even"'; }

    echo ' style="height:30px" onclick="highlightRow('.$row.');">
    <td><input type="checkbox" name="'.$kanda_id.'" id="check_'.$kanda_id.'" onchange="if(!this.checked) {$(\'#check_all\').prop(\'checked\', false)}" /></td>
    <td class="left-align" >'.$kanda_id.'</td>
    <td>'.$kanda_name.'</td>
    <td class="right-align bold" >'.$idadi.'</td>
    </tr>
        ';
       
        $row++;
    }
//}
?>

</table>

</form>
======== end of rpt_kandas_grid.php===========

=========start 0f rpt_print_reports.php ====================
{This one fetches records from the database perfectly and displays them when NOT used in div.}

<?php

include('../../config.php');
include('../../functions/common.php');
include('../../functions/sadaka.php');
include('../../labels/sadaka.php');

$members = array_keys($_POST);
$count = 1;


 ?>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>SDA - Print Membership Report</title>
<link rel="stylesheet" type="text/css" href="<?php echo $root; ?>css/rpt_member.css" />
<style>
    thead,th {
         text-align: centre;
         background-color:rgb(200,200,200);
    }
    tbody {
      border:1px solid black;
      text-align: left;
    }
    tfoot {color:red;}
   
    table #t01{
        border-collapse:collapse;
        width: 100%;
        border:1px solid rgb(100,100,100);
   
    }
    caption {
      text-align: center;
      font-size: 16px;
      font-weight: bold;
      background-color:#eee;
    }
   
    table #t02,tr{
        border-collapse:collapse;
        width: 100%;
        border: 1px solid black;
        empty-cells: show;
    }
    tr.d0 td {
        background-color: #CC9999; color: black;
    }
    tr.d1 td {
        background-color: #9999CC; color: black;
    }
    td{
        padding: 5px;
     }
</style>
</head>

<body >
<center>
<div style="padding:5px 15px; border-bottom:1px dashed rgb(200,200,200)">
        <table  style="rgb(100,100,100)">
       
            <tr>
                <td style="width:50px; vertical-align:top">
                <img src="../../images/logo.gif" style="width:60px;" alt="sda_logo" />
                </td>

                <td style="text-align:center">
                <span style="font-family: Script MT; font-weight: bold; font-size:20px">Ukonga Seventh-day Adventist Church</span><br />
                <span style="font-size:20px">Eastern Tanzania Conference</span><br />
                <span style="font-size:16px">S.L.P 5034, Dar es Salaam</span>
                </td>

            </tr>
        </table>
</div>
</center>

    <table id="t02" border='1' cellpadding='0' cellspacing='0'>
     <caption >Church Members Including Regular Worshippers</caption>
      <thead>
     
           <tr>
            <th >S/N</th>
            <th>Member#</th>
            <th>Name</th>
            <th>Gender</th>
            <th>Marital Status</th>
            <th>Kanda</th>
            <th>Member Type</th>
            <th>Address</th>
            <th>Phone</th>
            <th>Email</th>
            <th>Economic Status</th>
           
        </tr>
     </thead>   
<?php   
 
echo '<tbody>';

foreach($members as $kanda_id) {
   
        echo print_receipt($kanda_id);
       
     
}

echo ' </tbody>

</table>

</body>
</html>';


function print_receipt($kanda_id) {
    global $connection;
    global $count;
   
    $sql ="SELECT kandas.kandaname, memberships.memberid,memberships.firstname,memberships.middlename,memberships.surname,memberships.gender,
            memberships.marital_status,memberships.email,memberships.address,memberships.phone,memberships.town,memberships.postcode,
            memberships.economic_status,district.district,region.region,membershiptypes.type_name FROM memberships
            LEFT JOIN kandas ON memberships.kanda_id = kandas.kanda_id
            LEFT JOIN district ON memberships.district = district.code
            LEFT JOIN region ON memberships.region = region.code
            LEFT JOIN membershiptypes ON memberships.membershiptype_id = membershiptypes.id
            WHERE memberships.kanda_id='$kanda_id'";
   


    $data = $connection->query($sql);
   
    $data -> setFetchMode(PDO::FETCH_ASSOC);
    //$kanda_num = $data->rowCount();
   
    while($members = $data->fetch()) {
           $fullname = ucfirst($members['firstname']).' '.ucfirst($members['middlename']).' '.ucfirst($members['surname']);
        $kanda = $members['kandaname'];
        $address = $members['town'].' - ' .$members['district']. ', P.O.BOX ' .$members['address'].' '.  $members['region'].' ' .  $members['postcode'];
        $memberid = $members['memberid'];
        $membertype = $members['type_name'];
        $gender = ($members['gender']) == 'F' ? 'Female' : 'Male';
        $phone = $members['phone'];
        $email = $members['email'];
        $economy = $members['economic_status'];
        $marital=$members['marital_status'];
       
        switch ($marital) {
         case 'M':
            $marital_status ='Married';
            break;
         case 'D':
           $marital_status ='Divorced';
            break;
         case 'W':
            $marital_status ='Widow(er)';
            break;
        Default:
            $marital_status ='Single';
            break;
        }   
       
      switch ($economy) {
         case 'E':
            $economic_status ='Employed';
            break;
         case 'N':
           $economic_status ='Un-employed';
            break;
         case 'R':
            $economic_status ='Entrepreneur';
            break;
        Default:
           $economic_status ='Student';
            break;
        }   
       
           
        echo "<tr class=\"d".($count % 2)."\">";
             echo "<td>";
            echo $count;
            echo "</td>";

            echo "<td>";
            echo $memberid;
            echo "</td>";
           
            echo "<td>";
            echo $fullname;
            echo "</td>";
           
            echo "<td>";
            echo $gender;
            echo "</td>";
           
            echo "<td>";
            echo $marital_status;
            echo "</td>";
           
            echo "<td>";
            echo $kanda;
            echo "</td>";
           
            echo "<td>";
            echo $membertype;
            echo "</td>";
           
            echo "<td>";
            echo $address;
            echo "</td>";
           
            echo "<td>";
            echo $phone;
            echo "</td>";
           
            echo "<td>";
            echo $email;
            echo "</td>";
           
            echo "<td>";
            echo $economic_status;
            echo "</td>";
      echo "</tr>";
       $count++;
     
    }
 // $count = $kanda_num;
/*
    $member = '
    <!--<div id="report" align=center>-->
    <div style="font-family:Times new roman; width:700px; background-color:rgb(255,255,255); text-align:left; padding:5px">
    <tbody>
        <tr height=20 style="height:15.0pt">
          <td height=20 class=xl7131894 style="height:15.0pt;border-top:none">1</td>
          <td class=xl6331894 style="border-top:none;border-left:none">'.strtoupper($fullname).'</td>
          <td class=xl6331894 style="border-top:none;border-left:none">&nbsp;</td>
        </tr>
  </tbody>
   
    </table>

   
    </div>

    ';
   
    return $member; */
}
echo '</div>';
?>
==========end of rpt_print_reports====================================


thanks for your kindest help.