PHP 无法为每个数组回显



我试图用每个回显一个数组,但它不显示任何值。i只能在一秒内回显每个值。

谁能告诉我我做错了什么?

我想回应的是价格、产品、描述等,但我什么也得不到。

如果你需要查看数组的输出就在这里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
}

当前它看起来像$subitem包含一个长度为1的数组,其中第一个索引是一行。改变…

$superitem[$row['itemid']][] = $row;
应该…

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

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

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

相关内容

  • 没有找到相关文章