I am trying to figure out the best way to handle this. The while loop puts all the data into an array, great! But, i want to group a set of results into an array and put it back into the $row array. And i am not sure how to do that.
The reason being that i want to run a function that will display icons if the grouped items have a value, and i figured grouping them would be easier to work with.
Here is what i have now, it throws an error Too few arguments to function icon(), and i understand why its throwing that.
function icon($pump, $product) {
if ($pump == 'Yes') {
return "<img src='.." . IMAGES . "icons/icon-pump.png' alt='Trailer has a Pump' class='trailer-icon'>";
}
if ($product == 'Yes') {
return "<img src='.." . IMAGES . "icons/icon-gas.png' alt='Trailer has Product' class='trailer-icon'>";
}
}
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$features = array(
'pump' => $row['trailer_pump'],
'product' => $row['trailer_product']
);
$data = "<tr>\r\n<td><a href='view-trailer.php?id=" . $row['trailer_id'] . "'>" . $row['trailer_number'] . "</a></td>\r\n"
. "<td>" . $row['first_name'] . " " . $row['last_name'] . "</td>\r\n"
. "<td>" . icon($features) . "</td>"
. "<td>" . $row['status_name'] . "</td>\r\n"
. "<td><a href='https://www.google.com/maps/search/?api=1&query=" . $row['trailer_lat'] . "," . $row['trailer_long'] . "' target='_blank'>View Map</a></td>\r\n"
. "</tr>\r\n";
print $data;
}
} catch (PDOException $e) {
print $e->getMessage();
}
Update The results i am looking for is:
Array
(
[id] => 1
[trailer_number] => 609
[trailer_annual] => 0000-00-00
[trailer_fiveyear] => 0000-00-00
[trailer_compartments] => 4
[features] => array (
[pump] => Yes
[product] =>
)
[trailer_compart1] => 3000
[trailer_compart2] => 2000
[trailer_compart3] => 3000
[trailer_compart4] => 2000
[trailer_compart5] =>
)
$features = array('pump' => array(/*all pumps*/), 'product' => array(/*all products*/))?. "<td>" . icon($features) . "</td>"is obviously missing a parameter!