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 608711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:29:21+00:00 2026-05-13T17:29:21+00:00

I don’t know how to set up that the id field to print one

  • 0

I don’t know how to set up that the id field to print one by one per row in the script below which works wonders.

$tree = array();
 $sql = "select * from products
     left join product_varieties on product_varieties.product_id = products.id";
 $sth = query($sql);
 while($row = fetch($sth)) {
    $id = $row['id'];
    $tree[$id]['name'] = $row['name'];
    if($row['variety'])
       $tree[$id]['varieties'][] = $row;
 }

foreach($tree as $product)
    <div>
    echo $product['name']
    foreach($product['varieties'] as $variety)
         etc etc
    </div>

I have been trying to use the id generated in the while loop inside the form action url string inside the foreach parent as you use the name index in the partent foreach. I have tried echoing and printing some how it won’t display the id or if I print it, then it will appear three rows of ids per rows like 111333444555, I just want to be able to have the id per row like echo $product[‘name’] does, each iteration only prints one row of the index [ ‘name’].

The form below won’t echo anything, and I I change it to print then it will print 111222333444 help..

 foreach($tree as $product){
 <form action="cart.php?id="'. echo $product['id']. '">
</form> 
<div> echo $product['name'] echo $procude['id']
 foreach($product['varieties'] as $variety) {
etc etc 
</div> 
}
}
  • 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-13T17:29:21+00:00Added an answer on May 13, 2026 at 5:29 pm

    not sure i understand correctly what you want.. but let me try:

    foreach($tree as $id=>$product){
        echo "<div>".$id." ".$product['name'];
        foreach($product['varieties'] as $variety){
           // whatever 
        }
    
        echo "</div>";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Don't think that I'm mad, I understand how php works! That being said. I
I don't know: if this works. if it's a good idea. what it is
Don't know where else to ask, but from one day to the other my
Don't know the term for the red validation border, does it have one? I
Don't know if there is a better way to do this, so that is
Don't know how to frase this but I found this code wich works as
Don't know if it's stupid or reasonable question. I have methods which returns float/int
don't know if the title describes anything about what I'm trying to say but
don't know what happened in my jcrop selection. I think I pressed some keys
Don't really know how to formulate the title, but it should be pretty obvious

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.