This is likely a dense question, seeing as I began learning how to script only a few weeks ago, but how do I get the values echoed in the first foreach statement of my code to group in the same div (rather than creating a new one on each loop)? Basically, I want to format them as a group in one container or table independent of the images echoed in the second foreach.
$alpharray = array();
while ($row = mysqli_fetch_assoc($result)) {
$alpharray[$row['letter']][] = $row;
}
foreach (str_split($_POST['search_term']) as $alpha) {
echo "<img class='clickable' img src='../Letterproject/images/{$alpharray[$alpha][0]['photoPath']}' width='100' height='140'></src></a>";
echo '<div class="editable">';
foreach ($alpharray[$alpha] as $tempvar) {
echo "<a href ='findall.php'><img src='../Letterproject/images/{$tempvar['photoPath']}' width='70' height='110'></src></a>";
}
echo '</div>';
}
For context, the application takes characters from a form and matches them as attributes to images in mysql. I pass these images to a div and use jquery to enable a user to click on an image to see corresponding editable images. Right now the output from the code for a form entry like T-H-E is Ttt Hhh Eee but I really want clickable T-H-E and then editable tt hh ee, if that makes sense.
Thanks so much for ideas or critical angle on what I’m trying to do with what I have.
Use arrays to store your values and then
implodethem to output them. You do not have to use arrays, you can use strings and concatenate them too.This should work – The
$firstarray is a list of all the image tags, while the$secondarray is a list of all the<div>elements.