So we have a database that is used for history purposes to display businesses with their start and end dates, affiliated persons, historical notes, and associated newspaper clippings. Currently, when a user searches, for example (See Current Results), Arnold & Dunn, 2 results return, one with the affiliated person as 'Arnold', and the other with the affiliated person as 'Dunn". Group in the Sql Query on returns the first affiliated person. I was wondering how do you take x number of results for names and basically Concat them in PHP to show under one company result?
Current Results:
Arnold & Dunn Bicycle sales
Affiliated Person: Edwin L. Arnold
Year Established: 1886
Year Closed: 1888
Product/Service: Sporting Goods Stores
NAICS: 451110
Arnold & Dunn Bicycle sales
Affiliated Person: James R. Dunn
Year Established: 1886
Year Closed: 1888
Product/Service: Sporting Goods Stores
NAICS: 451110
Expected Results:
Arnold & Dunn Bicycle sales
Affiliated Person: Edwin L. Arnold, James R. Dunn
Year Established: 1886
Year Closed: 1888
Product/Service: Sporting Goods Stores
NAICS: 451110
PHP Search/Results Script:
<?php
require_once 'php/db.php';
$conn = dbConnect();
$OK = true;
if (isset($_GET['name'])) {
$data = "%".$_GET['name']."%";
$sql = 'SELECT *
FROM company
LEFT JOIN xref_ap_comp
ON company.CompId=xref_ap_comp.CompID
LEFT JOIN persons
ON xref_ap_comp.APID=persons.APID
LEFT JOIN xref_comp_prod2
ON company.CompId=xref_comp_prod2.CompID
LEFT JOIN product
ON xref_comp_prod2.NAICS=product.NAICS
LEFT JOIN product2
ON product.NAICSThreeDigitCode=product2.NAICSThreeDigitCode
LEFT JOIN product3
ON product2.NAICSRootCode=product3.NAICSRootCode
WHERE CompName like ?
ORDER BY company.CompName';
$stmt = $conn->prepare($sql);
$results = $stmt->execute(array($data));
$rows = $stmt->fetchAll();
$error = $stmt->errorInfo();
}
if(empty($rows)) {
echo "<h3>No Records Found</h3>";
}
else { foreach ($rows as $row) {
echo "<h3 class=\"ui-accordion-header ui-state-default ui-corner-all ui-accordion-icons\" role=\"tab\" id=\"ui-id-1\" aria-selected=\"false\" aria-expanded=\"false\" tabindex=\"0\">".$row['CompName']."<span class=\"ui-accordion-header-icon ui-icon ui-icon-triangle-1-e\"></span></h3>";
echo "<div>";
echo "<p>".$row['HistoricalNotes']."</p>";
echo "<ul>";
echo "<li>Affiliated Person: ".$row['APFirstName']." ".$row['APLastName']."</li>";
echo "<li>Year Established: ".$row['StartDate']."</li>";
echo "<li>Year Closed: ".$row['EndDate']."</li>";
echo "<li>Product/Service: ".$row['ProductCategory']."</li>";
echo "<li>NAICS: ".$row['NAICS']."</li>";
echo "</ul>";
echo "</div>";
}
}
I am guessing in the echo "<li>Affiliated Person: ".$row['APFirstName']." ".$row['APLastName']."</li>";
there would have to be some count object in order to recieve comma deliniated results (Affiliated Person: Edwin L. Arnold, James R. Dunn). Please let me know if there is any other required information needed to help on this issue.