I have the following function:
function getSystemNames($dbh, $myid) {
$sql = $dbh->prepare('
SELECT system_name
FROM product_systems
WHERE user_id = :myid
ORDER BY `system_name` ASC
');
$sql->bindValue('myid', $myid);
$sql->execute();
return $sql;
}
;
I then have the following code mixed in with my HTML:
<select id='group' class='select' name='group'><option value='000'>None</option>
<?php
$results = getSystemNames($dbh, $myid);
while ($row1 = $results->fetch(PDO::FETCH_ASSOC)){
echo "<option value='$row1[system_name]'>$row1[system_name]</option>";
}
?>
</select>
I am trying to merge the two so I don’t have as much code in my HTML but I haven’t been able to figure it out for the past hour and am looking for some help from the community. I have tried to no avail:
function getSystemNames($dbh, $myid) {
$sql = $dbh->prepare('
SELECT system_name
FROM product_systems
WHERE user_id = :myid
ORDER BY `system_name` ASC
');
$sql->bindValue('myid', $myid);
$sql->execute();
while ($row1 = $sql->fetch(PDO::FETCH_ASSOC)) {
return "<option value='$row1[system_name]'>$row1[system_name]</option>";
}
}
;
It’l return a multi-dimensional array. then use a
foreachin your html part to get the desired output.P.S. you don’t need
;after}here.