SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict Feudalism's Avatar
    Join Date
    Jun 2002
    Location
    Buenos Aires, Argentina
    Posts
    361
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question mysql_fetch_array updated

    My intention is to track duplicate entryes of records sellings and merge the quantities in one, and delete the other. Eg:

    1, Record Blue , 9
    2, Record Blue , 10
    3, Record Red , 3

    Should be like this:

    1, Record Blue, 19
    3, Record Red, 3

    using this code, it appears that all the records are selected when they have estado = 1. In the second loop, called "ordenes2", some of those records are set estado = 0, so, they should not be selected when the first recordset reaches them in the table, but they do.



    PHP Code:

    $sql
    ="select * from records where estado =1  order by id desc ";
    $rsproc=mysql_query($sql);
    while(
    $ordenes mysql_fetch_array($rsprocMYSQL_ASSOC)){

    $sqlh="select * from records where estado =1 and id <> " $ordenes[id];
    $rsproc2=mysql_query($sql);
    while(
    $ordenes2 mysql_fetch_array($rsproc2MYSQL_ASSOC)){    
    // some work, etc...
    $sql="update records set estado= 0 where id= "$ordenes2[id];
    }


  2. #2
    SitePoint Enthusiast
    Join Date
    Oct 2007
    Posts
    97
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Try using group by clause of SQL and it will make this simple.

    Cheers,

    ~Maneet
    Maneet Puri
    Lexolution IT Services


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •