MHenry
asked on
php zencart - having problems with attributes array
The basic problem is, when the form is submitted it should also include the product, the attribute and the model. The product and model work fine, but the attribute always just says "Array."
There are two places where $product['attributes'] shows up in this foreach loop. The first section is what prints the product, attribute and model on the page that also has the form. So I know the attributes are getting to the page.
The part later is where the problem occurs. I can't figure out why the same thing later in the code returns only the word "Array." This souldn't be that hard, it does print out the attribute on the page. This is really making me feel stoopid but I just don't see what's wrong.
Can anyone help me on this? I'm really stumped...
Here's the code:
<!-- Loop through all products /-->
<?php
foreach ($productArray as $product) {
?>
<tr class="<?php echo $product['rowClass']; ?>">
<td class="cartQuantity">
<?php
if ($product['flagShowFixedQu antity']) {
echo $product['showFixedQuantit yAmount'] . '<br /><span class="alert bold">' . $product['flagStockCheck'] . '</span><br /><br />' . $product['showMinUnits'];
} else {
echo $product['quantityField'] . '<br /><span class="alert bold">' . $product['flagStockCheck'] . '</span><br /><br />' . $product['showMinUnits'];
}
?>
</td>
<td class="cartQuantityUpdate" >
<?php
if ($product['buttonUpdate'] == '') {
echo '' ;
} else {
echo $product['buttonUpdate'];
}
?>
</td>
<td class="cartProductDisplay" >
<a href="<?php echo $product['linkProductsName ']; ?>"><span id="cartImage" class="back"><?php echo $product['productsImage']; ?></span><span id="cartProdTitle"><?php echo $product['productsName'] . '<span class="alert bold">' . $product['flagStockCheck'] . '</span>'; ?></span></a>
<br class="clearBoth" />
<?php
echo $product['attributeHiddenF ield'];
if (isset($product['attribute s']) && is_array($product['attribu tes'])) {
echo '<div class="cartAttribsList">';
echo '<ul>';
reset($product['attributes ']);
foreach ($product['attributes'] as $option => $value) {
?>
<li><?php echo $value['products_options_n ame'] . TEXT_OPTION_DIVIDER . nl2br($value['products_opt ions_value s_name']); ?></li>
<?php
}
echo '</ul>';
echo '</div>';
}
?>
</td>
<td class="cartUnitDisplay"><? php /*?><?php echo $product['productsPriceEac h']; ?><?php */?></td>
<td class="cartTotalDisplay">< ?php /*?><?php echo $product['productsPrice']; ?><?php */?></td>
<td class="cartRemoveItemDispl ay">
<?php
if ($product['buttonDelete']) {
?>
<a href="<?php echo zen_href_link(FILENAME_SHO PPING_CART , 'action=remove_product&pro duct_id=' . $product['id']); ?>"><?php echo zen_image($template->get_t emplate_di r(ICON_IMA GE_TRASH, DIR_WS_TEMPLATE, $current_page_base,'images /icons'). '/' . ICON_IMAGE_TRASH, ICON_TRASH_ALT); ?></a>
<?php
}
if ($product['checkBoxDelete' ] ) {
echo zen_draw_checkbox_field('c art_delete []', $product['id']);
}
?>
</td>
</tr>
<?php
//Begin Adding of New features
//$productsimage = $product['productsImage'];
$productsname = $product['productsName'];
$attributes = $value;
$products_options_name = $value['products_options_n ame'];
$arr_product_list[] = "<strong>Product Name:</strong> $productsname <br />";
$arr_product_list[] .= "<strong>Attributes:</stro ng> $attributes <br />";
$arr_product_list[] .= "<strong>Products Options Name:</strong> $products_options_name <br />";
$arr_product_list[] .= "------------------------- ---------- ---------- ---------- --------";
//End Adding of New features
} // end foreach ($productArray as $product)
?>
<!-- Finished loop through all products /-->
There are two places where $product['attributes'] shows up in this foreach loop. The first section is what prints the product, attribute and model on the page that also has the form. So I know the attributes are getting to the page.
The part later is where the problem occurs. I can't figure out why the same thing later in the code returns only the word "Array." This souldn't be that hard, it does print out the attribute on the page. This is really making me feel stoopid but I just don't see what's wrong.
Can anyone help me on this? I'm really stumped...
Here's the code:
<!-- Loop through all products /-->
<?php
foreach ($productArray as $product) {
?>
<tr class="<?php echo $product['rowClass']; ?>">
<td class="cartQuantity">
<?php
if ($product['flagShowFixedQu
echo $product['showFixedQuantit
} else {
echo $product['quantityField'] . '<br /><span class="alert bold">' . $product['flagStockCheck']
}
?>
</td>
<td class="cartQuantityUpdate"
<?php
if ($product['buttonUpdate'] == '') {
echo '' ;
} else {
echo $product['buttonUpdate'];
}
?>
</td>
<td class="cartProductDisplay"
<a href="<?php echo $product['linkProductsName
<br class="clearBoth" />
<?php
echo $product['attributeHiddenF
if (isset($product['attribute
echo '<div class="cartAttribsList">';
echo '<ul>';
reset($product['attributes
foreach ($product['attributes'] as $option => $value) {
?>
<li><?php echo $value['products_options_n
<?php
}
echo '</ul>';
echo '</div>';
}
?>
</td>
<td class="cartUnitDisplay"><?
<td class="cartTotalDisplay"><
<td class="cartRemoveItemDispl
<?php
if ($product['buttonDelete'])
?>
<a href="<?php echo zen_href_link(FILENAME_SHO
<?php
}
if ($product['checkBoxDelete'
echo zen_draw_checkbox_field('c
}
?>
</td>
</tr>
<?php
//Begin Adding of New features
//$productsimage = $product['productsImage'];
$productsname = $product['productsName'];
$attributes = $value;
$products_options_name = $value['products_options_n
$arr_product_list[] = "<strong>Product Name:</strong> $productsname <br />";
$arr_product_list[] .= "<strong>Attributes:</stro
$arr_product_list[] .= "<strong>Products Options Name:</strong> $products_options_name <br />";
$arr_product_list[] .= "-------------------------
//End Adding of New features
} // end foreach ($productArray as $product)
?>
<!-- Finished loop through all products /-->
ASKER
HackneyCab,
Thanks for taking a look at this. I've been stuck on it for a couple weeks so I appreciate any help I can get.
I'm not sure which variable I should be looking at. Would it be $product['attributes']? Would that work in your example?
Here's the thing, the above code renders the product, model and attribute on the page already and they all work. I think this is the code that does it:
<?php
echo $product['attributeHiddenF ield'];
if (isset($product['attribute s']) && is_array($product['attribu tes'])) {
echo '<div class="cartAttribsList">';
echo '<ul>';
reset($product['attributes ']);
foreach ($product['attributes'] as $option => $value) {
?>
a little later in the code is where the product, model and attribute are setup to email:
//Begin Adding of New features
//$productsimage = $product['productsImage'];
$productsname = $product['productsName'];
$attributes = $value;
$products_options_name = $value['products_options_n ame'];
$arr_product_list[] = "<strong>Product Name:</strong> $productsname <br />";
$arr_product_list[] .= "<strong>Attributes:</stro ng> $attributes <br />";
$arr_product_list[] .= "<strong>Products Options Name:</strong> $products_options_name <br />";
$arr_product_list[] .= "------------------------- ---------- ---------- ---------- --------";
And only the attributes isn't working. I was wondering if it has to do with that reset in the first snippet. I've never seen that one before.
Thanks,
MH
Thanks for taking a look at this. I've been stuck on it for a couple weeks so I appreciate any help I can get.
I'm not sure which variable I should be looking at. Would it be $product['attributes']? Would that work in your example?
Here's the thing, the above code renders the product, model and attribute on the page already and they all work. I think this is the code that does it:
<?php
echo $product['attributeHiddenF
if (isset($product['attribute
echo '<div class="cartAttribsList">';
echo '<ul>';
reset($product['attributes
foreach ($product['attributes'] as $option => $value) {
?>
a little later in the code is where the product, model and attribute are setup to email:
//Begin Adding of New features
//$productsimage = $product['productsImage'];
$productsname = $product['productsName'];
$attributes = $value;
$products_options_name = $value['products_options_n
$arr_product_list[] = "<strong>Product Name:</strong> $productsname <br />";
$arr_product_list[] .= "<strong>Attributes:</stro
$arr_product_list[] .= "<strong>Products Options Name:</strong> $products_options_name <br />";
$arr_product_list[] .= "-------------------------
And only the attributes isn't working. I was wondering if it has to do with that reset in the first snippet. I've never seen that one before.
Thanks,
MH
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yes, exactly. The output just says Attributes: Array.
The bad news is, the code you supplied is generating
500 - Internal server error.
There is a problem with the resource you are looking for, and it cannot be displayed.
The bad news is, the code you supplied is generating
500 - Internal server error.
There is a problem with the resource you are looking for, and it cannot be displayed.
ASKER
Not that I know much of what's going on, but this
echo $value['products_options_n ame'] . TEXT_OPTION_DIVIDER . nl2br($value['products_opt ions_value s_name']). ", ";
looks like it's related to the third line down in your code:
$arr_product_list[] .= "<strong>Products Options Name:</strong> $products_options_name <br />";
the Products option name is working, it's the array that's hosed.
Best,
MH
echo $value['products_options_n
looks like it's related to the third line down in your code:
$arr_product_list[] .= "<strong>Products Options Name:</strong> $products_options_name <br />";
the Products option name is working, it's the array that's hosed.
Best,
MH
Sorry, I did intend to change echo to a variable append (in fact, I thought I had), but I meant this:
$arr_product_list[] = "<strong>Product Name:</strong> $productsname <br />";
$att_list = '';
foreach ($product['attributes'] as $option => $value) {
$att_list .= $value['products_options_n ame'] . TEXT_OPTION_DIVIDER . nl2br($value['products_opt ions_value s_name']). ", ";
}
$arr_product_list[] .= "<strong>Attributes:</stro ng>".$att_ list;
$arr_product_list[] .= <br />";
$arr_product_list[] .= "<strong>Products Options Name:</strong> $products_options_name <br />";
$arr_product_list[] .= "------------------------- ---------- ---------- ---------- --------";
Try that. I can't see anything in there which would cause a server error, but if you do get a 500 code, check your Apache error log file.
$arr_product_list[] = "<strong>Product Name:</strong> $productsname <br />";
$att_list = '';
foreach ($product['attributes'] as $option => $value) {
$att_list .= $value['products_options_n
}
$arr_product_list[] .= "<strong>Attributes:</stro
$arr_product_list[] .= <br />";
$arr_product_list[] .= "<strong>Products Options Name:</strong> $products_options_name <br />";
$arr_product_list[] .= "-------------------------
Try that. I can't see anything in there which would cause a server error, but if you do get a 500 code, check your Apache error log file.
ASKER
That still throws the 500 error.
I think the problem is the attributes and the product options are two different things. The product option is what generates the Model #. The attributes is what further identifies the product.
By the way, what's Apache? ;) This is on a windows server. Which is prolly about half the problem...
I think the problem is the attributes and the product options are two different things. The product option is what generates the Model #. The attributes is what further identifies the product.
By the way, what's Apache? ;) This is on a windows server. Which is prolly about half the problem...
ASKER
The only error in my log file is:
[25-Apr-2010 13:12:06] PHP Warning: PHP Startup: Unable to load dynamic library 'C:\Program Files\PHP\ext\php_mssql.dl l' - The specified module could not be found.
in Unknown on line 0
[25-Apr-2010 13:12:06] PHP Warning: PHP Startup: Unable to load dynamic library 'C:\Program Files\PHP\ext\php_mssql.dl
in Unknown on line 0
Apache is a web server (most PHP developers use it, so I wrongly presumed it was the software you were running).
Which web server are you using? You need to find the error log for the web server and find out any details you can about the 500 "internal server error" code that it's generating.
I really can't think of anything in the PHP code we're discussing that would cause the web server to choke like this.
Which web server are you using? You need to find the error log for the web server and find out any details you can about the 500 "internal server error" code that it's generating.
I really can't think of anything in the PHP code we're discussing that would cause the web server to choke like this.
ASKER
I was just kidding about the Apache thing. I know what Apache is.
This is on a windows server.
And the only error I get is what I pasted above:
[25-Apr-2010 13:12:06] PHP Warning: PHP Startup: Unable to load dynamic library 'C:\Program Files\PHP\ext\php_mssql.dl l' - The specified module could not be found.
in Unknown on line 0
This is on a windows server.
And the only error I get is what I pasted above:
[25-Apr-2010 13:12:06] PHP Warning: PHP Startup: Unable to load dynamic library 'C:\Program Files\PHP\ext\php_mssql.dl
in Unknown on line 0
ASKER
Maybe I'm pasting your code in the wrong area?
I'm pasting it over this:
$products_options_name = $value['products_options_n ame'];
$arr_product_list[] = "<strong>Product Name:</strong> $productsname <br />";
$arr_product_list[] .= "<strong>Attributes:</stro ng> $attributes <br />";
$arr_product_list[] .= "<strong>Products Options Name:</strong> $products_options_name <br />";
$arr_product_list[] .= "------------------------- ---------- ---------- ---------- --------";
is that right?
I'm pasting it over this:
$products_options_name = $value['products_options_n
$arr_product_list[] = "<strong>Product Name:</strong> $productsname <br />";
$arr_product_list[] .= "<strong>Attributes:</stro
$arr_product_list[] .= "<strong>Products Options Name:</strong> $products_options_name <br />";
$arr_product_list[] .= "-------------------------
is that right?
ASKER
Hey, got it working!
All I had to do was replace
$attributes = $$product['sttributes'];
with
$attributes = $value['products_options_v alues_name '];
I'm giving you the points though. Without your help it never would have occured to me that the attributes was actually products_options_values_na me.
Thanks so much for your help!
Best,
MH
All I had to do was replace
$attributes = $$product['sttributes'];
with
$attributes = $value['products_options_v
I'm giving you the points though. Without your help it never would have occured to me that the attributes was actually products_options_values_na
Thanks so much for your help!
Best,
MH
If you're seeing 'Array' unexpectedly then I recommend you investigate the variable using var_dump($variable_name) which will spit out a nicely spaced description of the variable. For the following array variable:
$array_variable = array(
'a string',
array('string within a nested array', 'and another'),
34,
new DateTimeZone('UTC')
);
you would get the following from var_dump($array_variable):
array(4) {
[0]=>
string(8) "a string"
[1]=>
array(2) {
[0]=>
string(28) "string within a nested array"
[1]=>
string(11) "and another"
}
[2]=>
int(34)
[3]=>
object(DateTimeZone)#1 (0) {
}
}
Once you've seen the internals of an array, it's much easier to work out what's going on and correct your code to work with that structure.
(By the way, if you want to be able to read the output of var_dump in an HTML page, wrap it in '<pre>' and '</pre>' so that the spacing is correctly rendered on the page. Also, if you use the xdebug extension for PHP, it will do that automatically, and it adds syntax colouring to the output to make it easier to read.)