Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6791335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:50:01+00:00 2026-05-26T17:50:01+00:00

This is likely a dense question, seeing as I began learning how to script

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T17:50:02+00:00Added an answer on May 26, 2026 at 5:50 pm

    Use arrays to store your values and then implode them to output them. You do not have to use arrays, you can use strings and concatenate them too.

    This should work – The $first array is a list of all the image tags, while the $second array is a list of all the <div> elements.

    $first = $second = array();
    foreach( str_split( $_POST['search_term']) as $alpha)
    { 
        $first[] = "<img class='clickable' img src='../Letterproject/images/{$alpharray[$alpha][0]['photoPath']}' width='100' height='140'></src></a>";
        $editable = array( '<div class="editable">');
        foreach ($alpharray[$alpha] as $tempvar)
        {                                              
             $editable[] = "<a href ='findall.php'><img src='../Letterproject/images/{$tempvar['photoPath']}' width='70' height='110'></src></a>";                                                         
        }   
        $editable[] = '</div>';
        $second[] = implode( '', $editable);
    }
    
    echo implode( '', $first);
    echo implode( '', $second);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is likely a duplicate of the below question but the only answer is
This is likely a stupid question but I always find myself wondering which is
I think this is likely to be a generic .NET assembly loading question, but
I know this is most-likely a simple question but when you restore a database
This is likely a novice question about LINQ, but assuming I have a set
This is likely a very simple question with a straightforward answer but I'm something
This is likely a a novice question, but google surprisingly did not provide an
This likely applies to non MVC too. But, Is it possible to use the
This is likely by design for big teams with proper QA departments, but we
This is most likely not an easy one but here is the situation: I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.