[PHP] Limit query results
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='#00' ?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
Re: [PHP] Limit query results
GROUP BY whatever_id_you_want in the SQL Dan Shirah skrev: 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='#00' ?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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Limit query results
SELECT DISTINCT? greets Zoltán Németh 2007. 05. 4, péntek keltezéssel 08.44-kor Dan Shirah ezt írta: 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='#00' ?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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Limit query results
Use SELECT DISTINCT in your SQL syntax. -- Miguel J. Jiménez Programador Senior Área de Internet/XSL/PHP [EMAIL PROTECTED] ISOTROL Edificio BLUENET, Avda. Isaac Newton nº3, 4ª planta. Parque Tecnológico Cartuja '93, 41092 Sevilla. Teléfono: 955 036 800 - Fax: 955 036 849 http://www.isotrol.com You let a political fight come between you and your best friend you have in all the world. Do you realize how foolish that is? How ominous? How can this country survive if friends can't rise above the quarrel. Constance Hazard, North South (book I) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Limit query results
Dan Shirah wrote: $result = mssql_query($sql) or die(mssql_error()); // print_r ($result); You realize that this will print the Resource ID# for the resource pointer, but not the actual result set. -- Jim Lucas Some men are born to greatness, some achieve greatness, and some have greatness thrust upon them. Unknown -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php