在一个数组中从两个选择查询中设置值

时间:2015-06-25 14:40:05

标签: php mysql arrays

我的两个选择查询是这样的,但我想获取单个数组中的所有记录如何从不同的选择查询中设置一个数组中的所有值

Text I Need
Also Text I need
第一个查询部分的

    $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'];
    }

    $rojmelArray = array();
    $l = 0;
    $selectRojmel = "SELECT DATE_FORMAT(rojmelDate,'%d-%m-%Y') AS rojmelDate,fine AS rojmelFine,amount AS rojmelAmt,rojTransType 
                        FROM rojmel
                    WHERE partyId = ".$partyId;
    $selectRojmelRes = mysql_query($selectRojmel);
    while($rojmelRow = mysql_fetch_array($selectRojmelRes))
    {
      $rojmelArray[$l]['rojmelDate']   = $rojmelRow['rojmelDate'];                 
      $rojmelArray[$l]['rojmelFine']   = $rojmelRow['rojmelFine'];                 
      $rojmelArray[$l]['rojmelAmt']    = $rojmelRow['rojmelAmt'];                 
      $rojmelArray[$l]['rojTransType'] = $rojmelRow['rojTransType'];                 
      $l++;
    } 

第二个查询部分

 {section name="sec" loop=$clientDetail}
     <td><a href="client.php?clientId={$clientDetail[sec].clientId}"><img src="img/edit.png"></a></td>
     <td>{$clientDetail[sec].particular}</td>
     <td>{$clientDetail[sec].cDate}</td>
     <td>{$clientDetail[sec].rate}</td>
     <td>{$clientDetail[sec].total}</td>
     <td>{$clientDetail[sec].kg}</td>
     <td>{$clientDetail[sec].totalAmt}</td>
  </tr>
  {/section}

2 个答案:

答案 0 :(得分:0)

尝试左外连接,它将结合来自两个表的结果,其中client表中的clientId等于rojmel表中的partyId。

$sql = "SELECT client.*, DATE_FORMAT(rojmelDate,'%d-%m-%Y') AS rojmelDate, fine AS rojmelFine, amount AS rojmelAmt, rojTransType FROM client LEFT OUTER JOIN rojmel on rojmel.partyId = clientId WHERE clientId = ".$clientId;

答案 1 :(得分:0)

我通过此查询得到了我的结果

SELECT client.*, DATE_FORMAT(rojmelDate,'%d-%m-%Y') AS rojmelDate, fine AS rojmelFine, amount AS rojmelAmt, rojTransType FROM client 
LEFT OUTER JOIN rojmel on rojmel.partyId = clientId WHERE client.`partyId`= ".$partyId;