Hi

I have two button in my page One is 'search' and another is 'print'
But i could not re direct and passing date to another page. code is working fine for search. But print
I am blur of this. Pls help me how i can redirect the page by using button click. Pls help me

Below my code

index.php

<?php
include_once '../inc/connection.inc.php';
?>

<?php
try {
       $stmt = $dbh->prepare('SELECT * FROM MVendorMaster order by MVName');
       $stmt->execute();
    } 
catch (PDOException $e) 
    {
       $output = 'Error fetching main vendor from database!';
       include '../errormsg.php';
       exit();
    }

foreach ($stmt as $row) 
    {
       $mvcode[] = array('MVCode' => $row['MVCode'], 'MVName' => $row['MVName']);
    }
include 'searchform.html.php';
?>

<?php
if (isset($_POST['search']) && $_POST['search']  != "" )
    {
        $mvcode = $_POST["mvendor"];
        $datefrom=$_POST["datefrom"];
        $dateto=$_POST["dateto"];

        $stmt = $dbh->query("SELECT * FROM php_vw_InvoiceHead WHERE MVCode='$mvcode' and SODate>='$datefrom' and SODate<='$dateto' ORDER BY MVCode,SODate");
        $stmt->setFetchMode(PDO::FETCH_ASSOC); 
        include 'view.html.php';

    }   

if (isset($_POST['print']) && $_POST['print']  != "" )
    {
        $mvcode = $_POST["mvendor"];
        $datefrom=$_POST["datefrom"];
        $dateto=$_POST["dateto"];

        $stmt = $dbh->query("SELECT * FROM php_vw_InvoiceHead WHERE MVCode='$mvcode' and SODate>='$datefrom' and SODate<='$dateto' ORDER BY MVCode,SODate");
        $stmt->setFetchMode(PDO::FETCH_ASSOC); 
        include 'print.html.php';

    }       

?>

searchform.html.php

<?php
include '../templete/header.php';
?>

<div>
    <h6>Sales Report by Main Vendor</h6>
</div>

<form action="" method="POST">
<table class="tdtable" id="tdtable">
                  <tr>
                  <td>Main Vendor Name </td>
                  <td>
                      <select name="mvendor" id="mvcode"><option value="">Mian Vendor</option>
                    <?php foreach ($mvcode as $mvcodes): ?>
                        <option value="<?php htmlout($mvcodes['MVCode']); ?>">
                            <?php htmlout($mvcodes['MVName']); ?></option>
                    <?php endforeach; ?>
                    </select>

                  </td>

              </tr>           
      <tr>
        <td>Date[From]:</td>
        <td><input type="text" id="datepicker1" name="datefrom" /></td>
      </tr>
      <tr>
        <td>Date[To]:</td>
        <td><input type="text" id="datepicker2" name="dateto" /></td>
      </tr>    
</table>
    <div>
        <input type="submit" value="Search" name="search">
        <input type="submit" value="Print" name="print">
    </div>
</form>

view.html.php

<?php  
$groupby = '';
$displaySubTotal = FALSE;
$subTotal = 0;
$grandTotal = 0;

$sub_balqty=0;  // maideen
$grn_balqty=0;  // maideen

$sub_rtnqty=0;  // maideen
$grn_rtnqty=0;  // maideen

$sub_qty=0;  // maideen
$grn_qty=0;  // maideen

?>


    <table width="100%" align="center" cellpadding="4" cellspacing="1" class=tbl_table">
        <tr>
   <td class="tbl_header">MV CODE</td>
    <td class="tbl_header">MV NAME</td>
    <td class="tbl_header">SO Date</td>
    <td class="tbl_header">SO No</td>
    <td class="tbl_header">RATE</td>
    <td class="tbl_header">SUPP.QTY</td>
    <td class="tbl_header">RTN.QTY</td>
    <td class="tbl_header">BAL.Qty</td>
    <td class="tbl_header">SOLD AMT</td>
    <td class="tbl_header">Actions</td>

        </tr>
        <?php if(isset($stmt))
        {
        while($row = $stmt->fetch()): 

              if($groupby!=$row['MVCode']): 
                if($displaySubTotal): ?>

                   <tr><td colspan="10"><hr /></td></tr>

                   <tr>

                        <td colspan="4">
                        <td class="tbl_subtotal_left" ><b>Sub Total </b></td>
                        <td class="tbl_subtotal_right"><b><?php echo number_format($sub_qty); ?></b></td>
                        <td class="tbl_subtotal_right"><b><?php echo number_format($sub_rtnqty); ?></b></td>
                        <td class="tbl_subtotal_right"><b><?php echo number_format($sub_balqty); ?></b></td>
                        <td class="tbl_subtotal_right"><b><?php echo number_format($subTotal,2); ?></b></td>
                    </tr>

                    <tr><td colspan="10"><hr /></td></tr>

               <?php 
                     $grandTotal += $subTotal; 
                     $subTotal = 0; 

                     $grn_balqty += $sub_balqty;
                     $sub_balqty=0;

                     $grn_rtnqty += $sub_rtnqty;
                     $sub_rtnqty=0;

                     $grn_qty += $sub_qty;
                     $sub_qty=0;
                else: 
                      $displaySubTotal = TRUE;
                endif; 
                      //$groupby = $row['SODate']; 
                      $groupby = $row['MVCode']; 
                endif; 
                ?>
            <tr>
                <td class="tbl_content"><?php echo $row['MVCode'];?></td>
                <td class="tbl_content"><?php echo $row['MVName'];?></td>
                <td class="tbl_content"><?php echo date("d-m-Y", strtotime($row['SODate']));?></td>
                <td class="tbl_content"><?php echo $row['SONo'];?></td>
                <td class="tbl_content_right"><?php echo number_format($row['Rate'],2) ;?></td>
                <td class="tbl_content_right"><?php echo number_format($row['Qty']) ;?></td>
                <td class="tbl_content_right"><?php echo number_format($row['RTNQty']) ;?></td>
                <td class="tbl_content_right"><?php echo number_format($row['BalQty']) ;?></td>
                <td class="tbl_content_right"><?php echo number_format($row['BalAmt'],2) ;?></td>
             </td>

            <?php 
                 $subTotal += $row['BalAmt']; 
                 $sub_balqty += $row['BalQty'];
                 $sub_rtnqty += $row['RTNQty'];
                 $sub_qty += $row['Qty'];

                 endwhile; 
                 $grandTotal += $subTotal; 
                 $grn_balqty += $sub_balqty;
                 $grn_rtnqty += $sub_rtnqty;
                 $grn_qty += $sub_qty;


             ?>
        <tr><td colspan="10"><hr /></td></tr>
        <tr>
            <td colspan="4">
                <td class="tbl_subtotal_left" ><b>Sub Total </b></td>
                <td class="tbl_subtotal_right"><b><?php echo number_format($sub_qty); ?></b></td>
                <td class="tbl_subtotal_right"><b><?php echo number_format($sub_rtnqty); ?></b></td>
                <td class="tbl_subtotal_right"><b><?php echo number_format($sub_balqty); ?></b></td>
                <td class="tbl_subtotal_right"><b><?php echo number_format($subTotal,2); ?></b></td>
        </tr>
        <!--
        <tr><td colspan="10"><hr /></td></tr>
        <tr>
            <td colspan="4">
            <td class="tbl_subtotal_left"><b>Grand Total</b></td>
            <td class="tbl_subtotal_right"><b><?php echo number_format($grn_qty); ?></b></td>
            <td class="tbl_subtotal_right"><b><?php echo number_format($grn_rtnqty); ?></b></td>
            <td class="tbl_subtotal_right"><b><?php echo number_format($grn_balqty); ?></b></td>
            <td class="tbl_subtotal_right"><b><?php echo number_format($grandTotal,2); ?></b></td>
        </tr>
        <tr><td colspan="10"><hr /></td></tr>
        -->
        <?php }?>
    </table>
   <?php unset($dbh); unset($stmt); ?>

<?php
include '../templete/footer.php';
?>

print.html.php

<?php
echo "print page";
?>

<script language="javascript" type="text/javascript">
     function printFunction(){

     window.print();
     }
</script>

<script language="javascript" type="text/javascript">

        function PrintGridData() {
            var prtGrid = document.getElementById('<%=txtDocNo%>');
            prtGrid.border = 0;
            var prtwin = window.open('', 'PrintGridViewData', 'left=100,top=100,width=1000,height=1000,tollbar=0,scrollbars=1,status=0,resizable=1');
            prtwin.document.write(prtGrid.outerHTML);
            prtwin.document.close();
            prtwin.focus();
            prtwin.print();
            prtwin.close();
 </script>

<?php  
$groupby = '';
$displaySubTotal = FALSE;
$subTotal = 0;
$grandTotal = 0;

$sub_balqty=0;  // maideen
$grn_balqty=0;  // maideen

$sub_rtnqty=0;  // maideen
$grn_rtnqty=0;  // maideen

$sub_qty=0;  // maideen
$grn_qty=0;  // maideen

?>


    <table width="100%" align="center" cellpadding="4" cellspacing="1" class=tbl_table">
        <tr>
   <td class="tbl_header">MV CODE</td>
    <td class="tbl_header">MV NAME</td>
    <td class="tbl_header">SO Date</td>
    <td class="tbl_header">SO No</td>
    <td class="tbl_header">RATE</td>
    <td class="tbl_header">SUPP.QTY</td>
    <td class="tbl_header">RTN.QTY</td>
    <td class="tbl_header">BAL.Qty</td>
    <td class="tbl_header">SOLD AMT</td>
    <td class="tbl_header">Actions</td>

        </tr>
        <?php if(isset($stmt))
        {
        while($row = $stmt->fetch()): 

              if($groupby!=$row['MVCode']): 
                if($displaySubTotal): ?>

                   <tr><td colspan="10"><hr /></td></tr>

                   <tr>

                        <td colspan="4">
                        <td class="tbl_subtotal_left" ><b>Sub Total </b></td>
                        <td class="tbl_subtotal_right"><b><?php echo number_format($sub_qty); ?></b></td>
                        <td class="tbl_subtotal_right"><b><?php echo number_format($sub_rtnqty); ?></b></td>
                        <td class="tbl_subtotal_right"><b><?php echo number_format($sub_balqty); ?></b></td>
                        <td class="tbl_subtotal_right"><b><?php echo number_format($subTotal,2); ?></b></td>
                    </tr>

                    <tr><td colspan="10"><hr /></td></tr>

               <?php 
                     $grandTotal += $subTotal; 
                     $subTotal = 0; 

                     $grn_balqty += $sub_balqty;
                     $sub_balqty=0;

                     $grn_rtnqty += $sub_rtnqty;
                     $sub_rtnqty=0;

                     $grn_qty += $sub_qty;
                     $sub_qty=0;
                else: 
                      $displaySubTotal = TRUE;
                endif; 
                      //$groupby = $row['SODate']; 
                      $groupby = $row['MVCode']; 
                endif; 
                ?>
            <tr>
                <td class="tbl_content"><?php echo $row['MVCode'];?></td>
                <td class="tbl_content"><?php echo $row['MVName'];?></td>
                <td class="tbl_content"><?php echo date("d-m-Y", strtotime($row['SODate']));?></td>
                <td class="tbl_content"><?php echo $row['SONo'];?></td>
                <td class="tbl_content_right"><?php echo number_format($row['Rate'],2) ;?></td>
                <td class="tbl_content_right"><?php echo number_format($row['Qty']) ;?></td>
                <td class="tbl_content_right"><?php echo number_format($row['RTNQty']) ;?></td>
                <td class="tbl_content_right"><?php echo number_format($row['BalQty']) ;?></td>
                <td class="tbl_content_right"><?php echo number_format($row['BalAmt'],2) ;?></td>
             </td>

            <?php 
                 $subTotal += $row['BalAmt']; 
                 $sub_balqty += $row['BalQty'];
                 $sub_rtnqty += $row['RTNQty'];
                 $sub_qty += $row['Qty'];

                 endwhile; 
                 $grandTotal += $subTotal; 
                 $grn_balqty += $sub_balqty;
                 $grn_rtnqty += $sub_rtnqty;
                 $grn_qty += $sub_qty;


             ?>
        <tr><td colspan="10"><hr /></td></tr>
        <tr>
            <td colspan="4">
                <td class="tbl_subtotal_left" ><b>Sub Total </b></td>
                <td class="tbl_subtotal_right"><b><?php echo number_format($sub_qty); ?></b></td>
                <td class="tbl_subtotal_right"><b><?php echo number_format($sub_rtnqty); ?></b></td>
                <td class="tbl_subtotal_right"><b><?php echo number_format($sub_balqty); ?></b></td>
                <td class="tbl_subtotal_right"><b><?php echo number_format($subTotal,2); ?></b></td>
        </tr>
        <!--
        <tr><td colspan="10"><hr /></td></tr>
        <tr>
            <td colspan="4">
            <td class="tbl_subtotal_left"><b>Grand Total</b></td>
            <td class="tbl_subtotal_right"><b><?php echo number_format($grn_qty); ?></b></td>
            <td class="tbl_subtotal_right"><b><?php echo number_format($grn_rtnqty); ?></b></td>
            <td class="tbl_subtotal_right"><b><?php echo number_format($grn_balqty); ?></b></td>
            <td class="tbl_subtotal_right"><b><?php echo number_format($grandTotal,2); ?></b></td>
        </tr>
        <tr><td colspan="10"><hr /></td></tr>
        -->
        <?php }?>
    </table>
   <?php unset($dbh); unset($stmt); ?>

<?php
include '../templete/footer.php';
?>

Pls help me

Maideen

I have changed some lines in your searchform.html.php
1) I created javascript searchorprint function
2) I named form as frm
3) I changed type from "submit" to "button"
4) on click on button I called function searchorprint

<?php
include '../templete/header.php';
?>

<script language="javascript" type="text/javascript">
     function searchorprint(type){
     if(type=='s')
     {
        document.frm.action='view.html.php';
        document.frm.submit();
     }
     if(type=='p')
     {
        document.frm.action='print.html.php';
        document.frm.submit();
     }


     }
</script>
<div>
    <h6>Sales Report by Main Vendor</h6>
</div>

<form action="" method="POST" name='frm' id='frm' >
<table class="tdtable" id="tdtable">
                  <tr>
                  <td>Main Vendor Name </td>
                  <td>
                      <select name="mvendor" id="mvcode"><option value="">Mian Vendor</option>
                    <?php foreach ($mvcode as $mvcodes): ?>
                        <option value="<?php htmlout($mvcodes['MVCode']); ?>">
                            <?php htmlout($mvcodes['MVName']); ?></option>
                    <?php endforeach; ?>
                    </select>

                  </td>

              </tr>           
      <tr>
        <td>Date[From]:</td>
        <td><input type="text" id="datepicker1" name="datefrom" /></td>
      </tr>
      <tr>
        <td>Date[To]:</td>
        <td><input type="text" id="datepicker2" name="dateto" /></td>
      </tr>    
</table>
    <div>
        <input type="button" value="Search" name="search" onclick="javascript:searchorprint('s')">
        <input type="button" value="Print" name="print"  onclick="javascript:searchorprint('p')">
    </div>
</form>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.