Comparing the results of two queries
Posted: Tue Sep 23, 2003 7:35 pm
I have two queries. Together they should create 1 list
(mod_edit: bbcode enabled)
Code: Select all
<?php
$q = mysql_query("SELECT * FROM C_PDF WHERE c_id = '7' AND a_by = '7'");
$r = mysql_fetch_array($q);
//This gives me the following result set
//C_PDF.cd_id = 7
//C_PDF.pdf_id = 123
//C_PDF.a_by = 7
//
//C_PDF.cd_id = 71
//C_PDF.pdf_id = 124
//C_PDF.a_by = 7
//Indicating that there are 2 entries (1 for pdf_id 123 and 1 for pdf_id 124)
$q2 = mysql_query("SELECT * FROM C_PDF WHERE c_id = '71' AND a_by = '7'");
$r2 = mysql_fetch_array($q2);
//This gives me the following result set
//C_PDF.cd_id = 71
//C_PDF.pdf_id = 124//also in the first result set
//C_PDF.a_by = 7
//
//C_PDF.cd_id = 7
//C_PDF.pdf_id = 230
//C_PDF.a_by = 7
//Indicating that there are 2 entries (1 for pdf_id 124 and 1 for pdf_id 230)
//I want to display a (CHECKED)checkbox form element
//beside pdf_id 124 in the second result set because it is also in
//the first result set, and I only want to display it once.
//I am trying to create a combined list out of the two result sets
//with (CHECKED) checkboxes by those in both result sets and
//(UNCHECKED) checkboxes by those in the first result set.
//I am having a terrible time with getting pdf_id 124 to display
//only once. Any help would be greatly appreciated.
?>