如何从查询中获取列值在另一个查询中使用它

时间:2014-11-02 06:56:42

标签: mysql

您好,我有两个名为students的表和属于的地址 学生记录。在这里,我有一个由两个表组成的查询或由两个表组成。

我需要将列(Addresses.phone)的值用于我定义的另一个查询 直接,但它没有工作。

以下是我的第一个查询,因此从此查询中我想将Addresses.Phone字段用于另一个 查询我该怎么做?

   <?php  //first query code

error_reporting('0');
  ob_start();
session_start();
if(!isset($_SESSION['email']))
{
  echo '<META HTTP-EQUIV="Refresh" Content="0; URL= ../../spd/myaccount.php">';
  exit();
}
else 
{
$email = $_SESSION['email'];
require_once('../../Admin Panel/db.php');

$query = "SELECT 
   properties.PropertyID,
   properties.PropertyType,
   properties.PropertyDealType,
   properties.Status,
   properties.PropostedPrice,
   properties.PropertyStatus,
   properties.RemoteEmployeeEmail,
   properties.PropertyDealerName,
   properties.PropertyOwnerName,
   remoteemployees.RemoteEmployeeID

   FROM  remoteemployees, properties

    WHERE remoteemployees.RemoteEmployeeEmail = properties.RemoteEmployeeEmail   

   AND  properties.RemoteEmployeeEmail = '".$email."'

   AND  properties.Status= 'Active'

   AND  properties.PropertyStatus= 'APPROVED'


   ORDER BY properties.PropertyID
   ";


  $query_run = $connection->query($query);
  if( $connection->error ) exit( $connection->error );
  while($res=$query_run->fetch_assoc()) {
                $count      =   $query_run->num_rows;          // Taking the number of queries returened by the result
                $array[]    =   $res;
  }
         ?>

//第二个查询代码:

<?php $queryemail= "SELECT SUM(transactions.EarnAmount) AS TotalEarn, transactions.TaxDeduction,

SUM(transactions.AmountPaid) AS TotalPaid from transactions WHERE transactions.RemoteEmployeeID = (remoteemployees.RemoteEmployeeID)---->This is from first query I want to use it here"; ?>

0 个答案:

没有答案