Re: array type problem

From: AJ (nospam_at_redcatmedia.net)
Date: 06/07/04


Date: Mon, 7 Jun 2004 08:17:15 +0000 (UTC)


"dogeater" <ggombo69@yahoo.com> wrote in message
news:7fcc8a1.0406061601.33ac913f@posting.google.com...
> andy@redcatmedia.net (AJ) wrote in message
news:<51cfbdd0.0406060332.14ff6567@posting.google.com>...
> > andy@redcatmedia.net (AJ) wrote in message
news:<51cfbdd0.0406051311.68d520a6@posting.google.com>...
> >
> > > This is the bit of code that I'm running:
> > >
> > > <?php do {
> > > $cart_total=$cart_total+$row_current_cart['product_price'];
> > > } while ($row_current_cart = mysql_fetch_assoc($current_cart));
> > > ?>
> >
> > And to actually make some sense of that now that my Mac is playing
> > again...
> >
> > Basically, what's happening is that the second time I try to print the
> > cart out, or parts of it, on one page, it's got to the end of the
> > array and prints nothing.
> >
> > I've tried reset($current_cart) but no joy.
> >
> > Any ideas please.
> >
> > Andy
>
> You might've typed in your snippet of code wrong here but I believe
> the while condition needs to have == not =.

Not sure about that. This works in as much as it displays the cart. The
problem I have is when I run this bit of code twice. I'm pretty sure that
the problem is because it loops through the array and displays the contents
of each element. Once it's finished at position 'n', the array counter
stays at position 'n'. What I need to do is run the code again from
position 0. I've even tried mysql_data_seek(0). This almost works but you
get:

[blank]
Product 1 £9.99
Total £19.98

when you run it the second time, even though there is only one item in the
cart. The first time it runs, it displays what it should.

Andy



Relevant Pages

  • Re: Strange behavior when working with large files
    ... > The first time I read a file it will read into the array in about 2 ... The second time I try to read a file in it ... The file I'm reading here consists of 1.5 million lines (50MB all ... that Perl needs as more time as longer the lines are. ...
    (comp.lang.perl.misc)
  • Re: Intense pace of play enforcement
    ... after I read your post a second time I ... I can't recommend avoiding Blackstone, ... and I'll probably want to play it again next summer. ... on a weekday, however, instead of taking a cart on a weekend. ...
    (rec.sport.golf)
  • trouble with arrays
    ... I'm trying to modify a shopping cart script from Mastering PHP/MySQL and am ... The original code, below, ... stores the cart items in a session variable array ...
    (comp.lang.php)
  • Re: "PHP and MySQL Web Development" by Luke Welling and Laura Thomson
    ... > adding something to the cart, and seeing the item in the cart, when then ... been supplanted, more recently, by the $_SESSION array. ... Look for "errata" for the book on the book publisher's website. ... Jeffrey D. Silverman | jeffrey AT jhu DOT edu ...
    (alt.php)
  • Reading an Input file twice
    ... If I want to format the output file with 50 characters I have all ... possible to save all values in an array. ... the max length and the second time to print it vai printf command. ... But so long the AWK programm was not finished, ...
    (comp.lang.awk)