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

  • Home
  • SEARCH
  • 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 6168557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:42:31+00:00 2026-05-23T22:42:31+00:00

I am trying to echo out an array using for each but it’s not

  • 0

I am trying to echo out an array using for each but it’s not displaying any values. The only values i can echo out is within a second for each.

Can anyone tell me what i’m doing wrong?

What i am trying to echo is the price, item, description etc but i am getting nothing.

If you need to see the output of the array it’s here http://operationbraveheart.org.uk/jcart/testshop.php

while ($row = $result->fetch()) { 
    $superitem[$row['itemid']][] = $row;
}
foreach($superitem AS $subitem) {
    list($prodid,$item,$size,$description,$price) = $subitem[0];

    if ($count % NUMCOLS == 0) echo "<tr>";  # new row
    echo '<td>'; 
    var_dump($subitem);
    //Your normal code up until the select box...
    echo '<form method="post" action="" class="jcart">
            <fieldset>
                <input type="hidden" name="jcartToken" value="'.$_SESSION['jcartToken'].'" />
                <input type="hidden" name="my-item-id" value="'.$subitem['prodid'].'" />
                <input type="hidden" name="my-item-price" value="'.$subitem['price'].'" />
                <input type="hidden" name="my-item-url" value="http://yahoo.com" />';

    if(count($subitem) > 1) {

        echo '<li><select name="my-item-name" id="foo">';
        foreach($subitem AS $subsubitem) {
            echo "<option value='".$subsubitem['size']."'>".$subsubitem['size']."</option>";
        }
        echo "</select></li>";
    }
    else {
        echo '<input type="hidden" name="my-item-name" value="'.$subitem['item'].'" />'; 
    }
    echo'<li>Price: $<span class="price">'.$subitem['price'].'</span></li>
                <li>
                    <label>Qty: <input type="text" name="my-item-qty" value="1" size="3" /></label>
                </li>
            </ul>

            <input type="submit" name="my-add-button" value="add to cart" class="button" />
        </fieldset>
    </form>';

    echo '</td>';
    $count++;
    $counter++;

    if ($count % NUMCOLS == 0) echo "</tr>\n";  # end row
}
  • 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-23T22:42:31+00:00Added an answer on May 23, 2026 at 10:42 pm

    Current it looks like $subitem contains an array of length 1 where the first index is a row. Change…

    $superitem[$row['itemid']][] = $row;
    

    should be…

    $superitem[$row['itemid']] = $row;
    

    and…

    list($prodid,$item,$size,$description,$price) = $subitem[0];
    

    should be…

    list($prodid,$item,$size,$description,$price) = $subitem;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to fill an array in php with variables, but it's not working
I am trying to fax out using sendfax but it wont work, when I
im trying to echo mediaplayer embed code with IF statement. is there any way
I'm trying to define a task that emits (using echo) a message when a
Trying to figure this out. I am trying to execute a perl script within
I'm trying to find out who the friends of 'x' are, and using that
Hi I'm trying to figure out how to echo back if the value entered
Ok, right now I trying to get a list to echo out from mysql
I am trying to build an array and I am looping through the values
I'm trying to access information in a previously created multidimensional array. Using print_r() ,

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.