Limit query results

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Good Morning everyone.

In the below code I am pulling records from two tables.  the records are
tied together by a common key in a 3rd table.  Everything works correctly
down to the $result.


// Connect to the database
 $connection = mssql_pconnect($host, $user, $pass) or die ('server
connection failed');
 $database = mssql_select_db("$database", $connection) or die ('DB
selection failed');
 // Query the table and load all of the records into an array.
  $sql = "SELECT
    support_payment_request.credit_card_id,
    support_payment_request.status_code,
    criminal_payment_request.credit_card_id,
    criminal_payment_request.status_code,
    credit_card_payment_request.credit_card_id,
    credit_card_payment_request.date_request_received
   FROM
    credit_card_payment_request LEFT OUTER JOIN support_payment_request
   ON support_payment_request.credit_card_id =
credit_card_payment_request.credit_card_id
    LEFT OUTER JOIN criminal_payment_request
   ON criminal_payment_request.credit_card_id =
credit_card_payment_request.credit_card_id
   WHERE support_payment_request.status_code = 'P'
   OR criminal_payment_request.status_code = 'P'";

   // print_r ($sql);
 $result = mssql_query($sql) or die(mssql_error());
          // print_r ($result);
 $number_rows= mssql_num_rows($result);
?>
<table width='780' border='1' align='center' cellpadding='2' cellspacing='2'
bordercolor='#000000'>
<?php
if(!empty($result)) {
while ($row= mssql_fetch_array($result)) {
 $id = $row['credit_card_id'];
 $dateTime = $row['date_request_received'];
 //print_r ($id);
?>
<tr>
<td width='88' height='13' align='center' class='tblcell'><div
align='center'><?php echo "<a href='javascript:editRecord($id)'>$id</a>"
?></div></td>
<td width='224' height='13' align='center' class='tblcell'><div
align='center'><?php echo "$dateTime" ?></div></td>
<td width='156' height='13' align='center' class='tblcell'><div
align='center'><?php echo "To Be Processed" ?></div></td>
<td width='156' height='13' align='center' class='tblcell'><div
align='center'><?php echo "Payment Type" ?></div></td>
<td width='156' height='13' align='center' class='tblcell'><div
align='center'><?php echo "Last Processed By" ?></div></td>
</tr>
<?php
}
}
?>

The picture below is what mu output looks like.  BUT, what I am trying to do
is have only ONE row returned per ID regardless of however many records may
be associated with that ID.   Below record number 122 has three results, I
only want one row for record 122 to be displayed.

Any ideas?


  2 <javascript:editRecord(2)>
Oct 6 2010 12:00AM
To Be Processed
Payment Type
Last Processed By
46 <javascript:editRecord(46)>
Feb 23 2007 2:27PM
To Be Processed
Payment Type
Last Processed By
66 <javascript:editRecord(66)>
Feb 26 2007 3:16PM
To Be Processed
Payment Type
Last Processed By
68 <javascript:editRecord(68)>
Feb 26 2007 3:39PM
To Be Processed
Payment Type
Last Processed By
76 <javascript:editRecord(76)>
Mar 21 2007 7:36AM
To Be Processed
Payment Type
Last Processed By
77 <javascript:editRecord(77)>
Mar 21 2007 7:40AM
To Be Processed
Payment Type
Last Processed By
78 <javascript:editRecord(78)>
Mar 21 2007 7:40AM
To Be Processed
Payment Type
Last Processed By
79 <javascript:editRecord(79)>
Mar 21 2007 7:41AM
To Be Processed
Payment Type
Last Processed By
122 <javascript:editRecord(122)>
Mar 27 2007 5:29PM
To Be Processed
Payment Type
Last Processed By
122 <javascript:editRecord(122)>
Mar 27 2007 5:29PM
To Be Processed
Payment Type
Last Processed By
122 <javascript:editRecord(122)>
Mar 27 2007 5:29PM
To Be Processed
Payment Type
Last Processed By

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux