• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1239
  • Last Modified:

Combining Recordsets in Dreamweaver

How do I combine two recordsets into one in Dreamweaver?  (MX2004) I am using PHP and MYSQL.
Explanation: This is an events page.  I have two recordsets, each one is pulling information from two identical tables located in separate databases (different connections), combining the data to produce one output of a complete list.
I have read up on the JOIN and UNION statements, just not sure exactly how to implement or what the syntax would be to implement this.  I am assuming I need a third recordset to combine the two.
Can anyone enlighten me?  
0
OwenSmart
Asked:
OwenSmart
1 Solution
 
v2MediaCommented:
There's no way to combine the results using DW behaviours or php's mysql functions.

The solution is to use php to loop out the results of both queries into the same array, then use the php array to output the records.

An example in psudocode is below:
<?php
//your DW recordsets here
 
//combine results into array
$arr_results = array();
 
//loop out first result into array
if($rsResult1_row) {
	
	$i = 0;
	
	do{
		
		$i++;
		$arr_results[$i]['dbColumn1'] = $rsResult1_row['dbColumn1'];
		$arr_results[$i]['dbColumn2'] = $rsResult1_row['dbColumn2'];
		$arr_results[$i]['dbColumn3'] = $rsResult1_row['dbColumn3'];
		$arr_results[$i]['dbColumn4'] = $rsResult1_row['dbColumn4'];
		
		
	  } while ($rsResult1_row = mysql_fetch_assoc($rsResult1_qry));
}
 
//loop out second result into array
if($rsResult2_row) {
	
	do{
		
		$i++;
		$arr_results[$i]['dbColumn1'] = $rsResult2_row['dbColumn1'];
		$arr_results[$i]['dbColumn2'] = $rsResult2_row['dbColumn2'];
		$arr_results[$i]['dbColumn3'] = $rsResult2_row['dbColumn3'];
		$arr_results[$i]['dbColumn4'] = $rsResult2_row['dbColumn4'];
		
		
	  } while ($rsResult2_row = mysql_fetch_assoc($rsResult2_qry));
}
 
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Combining Recordsets</title>
</head>
 
<body>
<table width="400" border="0" cellspacing="1" cellpadding="3">
  <tr>
    <th scope="col">dbColumn1</th>
    <th scope="col">dbColumn2</th>
    <th scope="col">dbColumn3</th>
    <th scope="col">dbColumn4</th>
  </tr>
<?php
	//loop out the array if results
	
	if(!empty($arr_results)) {
	
		foreach($arr_results as $k => $v {
	
	?>
  <tr>
    <td><?php echo $v['dbColumn1']; ?></td>
    <td><?php echo $v['dbColumn2']; ?></td>
    <td><?php echo $v['dbColumn3']; ?></td>
    <td><?php echo $v['dbColumn4']; ?></td>
  </tr>
<?php
 
		//end loop
		}
	//end if
	} else {
	//display no results
 
?>  
  <tr>
    <td colspan="4">
      <div align="center">no results to display</div>
    </td>
  </tr>
<?php
 
	//end display no results
	}
 
?>  
</table>
</body>
</html>

Open in new window

0
 
v2MediaCommented:
I can see a parse error on line 60. Change it to:

                foreach($arr_results as $k => $v) {
0
 
OwenSmartAuthor Commented:
tx, i will give this a try.

Is there any way to use UNION or JOIN to create the same result - keeping in mind that i have to connect to two different databases to retrieve the data, which is stored in identically structured tables.
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
v2MediaCommented:
As previously mentioned, no. You cannot interact with 2 mysql servers in the one query.
0
 
Jason C. LevineNo oneCommented:
>> You cannot interact with 2 mysql servers in the one query.

Correct.  One wonders why the data is spread out over two servers if the intent is to use it in this manner?
0
 
ImagineItDigitalCommented:
So is this NOT then considered a recordset?  This is the exact kind of thing I need, but I need it to be in a recordset.  This is because the page uses a Trigger that calls a recordset and emails that way.
0
 
v2MediaCommented:
No - it isn't. Use the solution posted to join the two recordsets in a php array.
0

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now