/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Shopping Cart – PHP code help

Hi,
I’m trying to create a shopping cart and I’m using XML as a database, which I’m not sure if it’s the correct thing to do. I was thinking about maybe using mySQL instead.

What I’m trying to accomplish is…I have several different bath & body products (Elite Hand Cream, Hand Cream, Body Mist, Bath Salts, Bath Soaks, etc) and each come in the same scents (40+ at the moment). I want to make it easier to update the pricing of one type of item (ie Bath Soak or Hand Cream, etc) instead of having to change 40+ buttons like I have to do with my paypal add to cart buttons…it takes way too long.

So what I’m trying to do is read the scent name and description from the XML file, put it into an array and display the scent name, description and quantity box. I want 4 scents per row. I want this function as a general template that I can use for each of the different products (Bath Salts, Body Mists, etc). What I’m getting is an error message b/c it is reading past 40, which is the last number in my array. It is attempting to get $productName[41] which doesn’t exist.

Here is my code:

function displayProducts() {

$count=0;
$i=0;

foreach(get_xml_nameDescription() as $product) {

$productName[$i]=$product->title;
$productDesc[$i]=$product->description;
$i++;
} //end for each

$count=count($productName);
$count–;

echo “<tr>”; // start of table product row

for ($y=0; $y<=$count; ) { // outer for loop to go through all products
$x=0; // reset x value to begin new table row

for ($x=0; $x<3; $x++) { // inner for loop to get 4 products per row

echo ‘<td width=”25%” valign=”center” align=”center”>

<table border=0 width=”100%” align=”center” cellspacing=3 cellpadding=3 valign=top>
<tr>
<td width=”75%”>
<div class=”prodTitle”>
<span>
<font face=”arial” size=”3″ color=”#3C5398″>
‘.$productName[$y].’
</font>
</span>
</div>
</td>

<td width=”25%” align=”left” valign=center>
<div class=”quantityBox”>
<span>
<font face=”arial” size=”2″ color=”#3C5398″>QTY:</font>
<input class=box type=textbox name=”qty” maxlength=3 ></input>

</span>
</div>
</td>
</tr>

<tr>

<td align=center colspan=2 valign=top>
<div class=”prodDesc”>
<span>
<font face=”arial” size=”2″ color=”#02670A”>
‘.$productDesc[$y].’
</font>
</span>
</div>
</td>
</tr>
</table><br></tr>’;

$y++;

} // end 4 product for loop

echo “</tr>”; // end product row

} //end outside for loop

} // end function

[B]Here is my error message:[/B]
Notice: Undefined offset: 41 in C:*****functions.php on line 52

Notice: Undefined offset: 41 in C:*****functions.php on line 75

I’m not very good in php. Is there a better way of doing what I want???

You can view my webpage to see the different products and scents I have to get an idea of what I’m trying to accomplish.

[url]http://www.coppercreekbathandbody.ca[/url]

I want to pass the cart to paypal once the cart is generated. I also only want to have 1 add to cart button which will add the quantities of each item on the page to the cart.

I hope this makes sense.

Any help or suggestions would be greatly appreciated.

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @mrzebra spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...