不能使用每个循环打印整个记录

时间:2015-06-20 06:40:32

标签: php mysql smarty

我的模板文件是这样的我尝试从数据库打印获取记录但问题是我的选择查询工作正常但在前面我不能打印整个记录我得到的结果它只打印第一条记录 哪个是我的错误,任何人都可以帮助我

    <table id="example" class="cell-border" cellspacing="0" width="100%" border="1">
      <tr>
        <td>Edit</td>
        <td>Particular</td>
        <td>Date</td>
        <td>Rate</td>
        <td>Diff</td>
        <td>Diff Amount</td>
        <td>Total</td>
        <td>K.G.</td>
        <td>Total Amount</td>
        <td>Javak Date</td>
        <td>Javak Fine</td>
        <td>Javak Amount</td>
        <td>Aavak Date</td>
        <td>Aavak Fine</td>
        <td>Aavak Amount</td>
      </tr>
      {foreach from=$clientDetail item=onerow}
       <input type="hidden" name="clientId" value="{$onerow.clientId}">
         <td><a href="client.php?clientId={$onerow.clientId}"><img src="img/edit.png"></a></td>
         <td>{$onerow.particular}</td>
         <td>{$onerow.cDate}</td>
         <td>{$onerow.rate}</td>
         <td>{$onerow.diff}</td>
         <td>{$onerow.diffAmt}</td>
         <td>{$onerow.total}</td>
         <td>{$onerow.kg}</td>
         <td>{$onerow.totalAmt}</td>
         <td>{$onerow.javkDate}</td>
         <td>{$onerow.javkFine}</td>
         <td>{$onerow.javakAmt}</td>
         <td>{$onerow.avakDate}</td>
         <td>{$onerow.avakFine}</td>
         <td>{$onerow.avakAmt}</td>
      </tr>
      {/foreach}
    </table>
    </form>
    {/block}

这是我的选择查询

<?php
include("include/config.inc.php");
if(!isset($_SESSION['s_activId']))
{
  $_SESSION['s_urlRedirectDir'] = $_SERVER['REQUEST_URI'];
  header("Location:checkLogin.php");
}
else
{
    $partyId = isset($_REQUEST['partyId']) ? $_REQUEST['partyId'] : 0;

    $k = 0;
    $clientDetail = array();
    $selectClient = "SELECT * FROM client
                     WHERE partyId = ".$partyId;
    $selectClientRes = mysql_query($selectClient);
    while($clientRow = mysql_fetch_array($selectClientRes))
    {
      $clientDetail[$k]['clientId']     = $clientRow['clientId'];
      $clientDetail[$k]['particular']   = $clientRow['particular'];
      $clientDetail[$k]['cliTransType'] = $clientRow['cliTransType'];
      $clientDetail[$k]['cDate']        = date('d-m-Y',strtotime($clientRow['cDate']));
      $clientDetail[$k]['rate']         = $clientRow['rate'];
      $clientDetail[$k]['diff']         = $clientRow['diff'];
      $clientDetail[$k]['diffAmt']      = $clientRow['diffAmt'];
      $clientDetail[$k]['total']        = $clientRow['total'];
      $clientDetail[$k]['kg']           = $clientRow['kg'];
      $clientDetail[$k]['totalAmt']     = $clientRow['totalAmt'];


      $selectCr = "SELECT rojmelDate AS javkDate,fine AS javkFine,amount AS javakAmt 
                        FROM rojmel
                   WHERE rojTransType = 'J'
                  AND partyId = ".$partyId;
      $selectCrRes = mysql_query($selectCr);
      while($clientRow = mysql_fetch_array($selectCrRes))
      {
        $clientDetail[$k]['javkDate'] = $clientRow['javkDate'];                 
        $clientDetail[$k]['javkFine'] = $clientRow['javkFine'];                 
        $clientDetail[$k]['javakAmt'] = $clientRow['javakAmt'];                 

      } 

      $selectCr = "SELECT rojmelDate AS avakDate,fine AS avakFine,amount AS avakAmt 
                        FROM rojmel
                   WHERE rojTransType = 'A'
                  AND partyId = ".$partyId;
      $selectCrRes = mysql_query($selectCr);
      while($clientRow = mysql_fetch_array($selectCrRes))
      {
        $clientDetail[$k]['avakDate'] = $clientRow['avakDate'];                 
        $clientDetail[$k]['avakFine'] = $clientRow['avakFine'];                 
        $clientDetail[$k]['avakAmt']  = $clientRow['avakAmt'];                 

      } 
     $k++;
    } 

    $z=0;
    $clientArray = array();
    $selectClient = "SELECT partyId,partyName
                       FROM party
                    WHERE partyType = 'C'";
    $selectClientRes = mysql_query($selectClient);
    while($clientRow = mysql_fetch_array($selectClientRes))
    {
      $clientArray['partyId'][$z]   = $clientRow['partyId'];
      $clientArray['partyName'][$z] = $clientRow['partyName'];
      $z++;
    }

    $selectAmount = "SELECT SUM(kg) AS jKg,SUM(totalAmt) AS jtotalAmt
                       FROM client
                      WHERE cliTransType = 'J'
                AND partyId = ".$partyId;
    $selectAmountRes = mysql_query($selectAmount);
    if($jrow = mysql_fetch_assoc($selectAmountRes))
    {
      $jKg          = $jrow['jKg'];
      $jtotalAmt    = $jrow['jtotalAmt'];

    }

    $selectAavkAmount = "SELECT SUM(kg) AS aKg,SUM(totalAmt) AS atotalAmt
                       FROM client
                      WHERE cliTransType = 'A'
                AND partyId = ".$partyId;
    $selectAavkAmountRes = mysql_query($selectAavkAmount);
    if($arow = mysql_fetch_assoc($selectAavkAmountRes))
    {
      $aKg          = $arow['aKg'];
      $atotalAmt    = $arow['atotalAmt'];  
    }

    $finalKg     = $aKg - $jKg;
    $finalAmount = $atotalAmt - $jtotalAmt;


    include("./bottom.php");
    $smarty->assign("crArray",$crArray);
    $smarty->assign("finalAmount",$finalAmount);
    $smarty->assign("finalKg",$finalKg);
    $smarty->assign("partyId",$partyId);
    $smarty->assign("clientDetail",$clientDetail);
    $smarty->assign("clientArray",$clientArray);
    $smarty->display("clientList.tpl");
}
?>

0 个答案:

没有答案