Reputation: 565
I've looked around and I can't figure out how to get the following block of code to work:
$answer17 = getAttachmentsByUser($dbh, $myid);
$attachment_table = while ($row73 = $answer17->fetch(PDO::FETCH_ASSOC)) {
echo '<tr>';
echo "<td><input name='checkbox[]' type='checkbox' id='checkbox[]' value='$row73[imageven_id]'></td>";
echo "<td><a href='../php/viewimages.php?id=$row73[image_id]')'>$row73[upload_name]</a></td>";
echo "<td>$row73[image_category]</td>";
echo "<td>$row73[upload_date]</td>";
echo '</tr>';
};
I've seen other examples of how to concatenate results from a while statement to build an array but I think what I need is more complicated. Is there a way to build the html table I want and then put it into a variable to be used elsewhere? The while statement works fine on its own, just not as a variable.
Upvotes: 0
Views: 35
Reputation: 2463
$answer17 = getAttachmentsByUser($dbh, $myid);
$attachment_table = '';
while (($row73 = $answer17->fetch(PDO::FETCH_ASSOC)) !== false) {
$attachment_table .= '<tr>';
$attachment_table .= "<td><input name='checkbox[]' type='checkbox' id='checkbox[]' value='${row73[imageven_id]}'></td>";
$attachment_table .= "<td><a href='../php/viewimages.php?id=${row73[image_id]}')'>${row73[upload_name]}</a></td>";
$attachment_table .= "<td>${row73[image_category]}</td>";
$attachment_table .= "<td>${row73[upload_date]}</td>";
$attachment_table .= '</tr>';
};
Upvotes: 1