So I figured out a possible way of doing this.
First step was to query for all records with a specific ID :
$q = "SELECT product_line FROM ordering_info2 WHERE wp_identifier='$id' GROUP BY product_line ORDER BY s_line ASC";
$r = mysql_query($q) or die(mysql_errno().": ".mysql_error());
while ($row = mysql_fetch_array($r)) {
$body .= "<tr>";
$body .= "<td colspan=\"2\">$row[product_line]</td>";
$body .= "</tr>";
Then, I would loop through those results and query them for all records pertaining to the current ID and the current product_line in the loop:
$q2 = "SELECT product_category FROM ordering_info2 WHERE product_line='$row[product_line]' AND wp_identifier='$id' GROUP BY product_category ORDER BY s_category ASC";
$r2 = mysql_query($q2) or die(mysql_errno().": ".mysql_error());
echo mysql_num_rows($r2);
while ($row2 = mysql_fetch_array($r)) {
print_r($row2);
$body .= "<tr>";
$body .= "<td colspan=\"2\">$row2[product_category]</td>";
$body .= "</tr>";
Now I want to actually output the specific technical data contained within the product_category and product_line we are currently in in the loop:
$q3 = "SELECT actual_id, wp_description FROM ordering_info2 WHERE product_line='$row[product_line]' AND product_category='$row2[product_category]' AND wp_identifier='$id' ORDER BY detail_sort ASC";
$r3 = mysql_query($q3) or die(mysql_errno().": ".mysql_error());
echo mysql_num_rows($r3);
while ($row3 = mysql_fetch_array($r3)) {
print_r($row3);
$body .= "<tr>";
$body .= "<td class=\"code\"><a href=\"http://www.mrv.com/products/how_to_buy.php?prod=$row3[actual_id]\">$row3[actual_id]</a></td>";
$body .= "<td>".nl2br($row3[wp_description])."</td>";
$body .= "</tr>";
}
}
}
echo $body;
However, the script is only outputting the stuff in the while loop for the product_line query - it prints out the header and then nothing else. And I receive no errors when I use die(mysql_error()).
I sure hope I'm on the right track. 🙁
Here's the full code:
$q = "SELECT product_line FROM ordering_info2 WHERE wp_identifier='$id' GROUP BY product_line ORDER BY s_line ASC";
$r = mysql_query($q) or die(mysql_errno().": ".mysql_error());
while ($row = mysql_fetch_array($r)) {
$body .= "<tr>";
$body .= "<td colspan=\"2\">$row[product_line]</td>";
$body .= "</tr>";
$q2 = "SELECT product_category FROM ordering_info2 WHERE product_line='$row[product_line]' AND wp_identifier='$id' GROUP BY product_category ORDER BY s_category ASC";
$r2 = mysql_query($q2) or die(mysql_errno().": ".mysql_error());
echo mysql_num_rows($r2);
while ($row2 = mysql_fetch_array($r)) {
print_r($row2);
$body .= "<tr>";
$body .= "<td colspan=\"2\">$row2[product_category]</td>";
$body .= "</tr>";
$q3 = "SELECT actual_id, wp_description FROM ordering_info2 WHERE product_line='$row[product_line]' AND product_category='$row2[product_category]' AND wp_identifier='$id' ORDER BY detail_sort ASC";
$r3 = mysql_query($q3) or die(mysql_errno().": ".mysql_error());
echo mysql_num_rows($r3);
while ($row3 = mysql_fetch_array($r3)) {
print_r($row3);
$body .= "<tr>";
$body .= "<td class=\"code\"><a href=\"http://www.mrv.com/products/how_to_buy.php?prod=$row3[actual_id]\">$row3[actual_id]</a></td>";
$body .= "<td>".nl2br($row3[wp_description])."</td>";
$body .= "</tr>";
}
}
}
echo $body;