limit problem when using update.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • canabatz
    New Member
    • Oct 2008
    • 155

    limit problem when using update.

    im trying to update my results and i get error:

    this is the code:
    Code:
    this is the select :
    SELECT * FROM `bidding_details` where `bid_id`='$bid_id' and `sortbid` = '1' order by bid_price asc limit 0, 50
    
    this is the update:"
    update bidding_details set sortbid = '0', rank = '0' where `bid_id`='$bid_id' and sortbid = '1' and `bid_price`='$remove_bid' LIMIT 0, 50
    if i do LIMIT 50 ,it's working ,when im puting 0, 50 ,i get error!
    i need update the results from the first 50 rows.

    what can be the error
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    What is the error text? In future, please remember to give us all of the information - it helps us help you.

    Good day,
    Mark.

    Comment

    • canabatz
      New Member
      • Oct 2008
      • 155

      #3
      sorry :)

      You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' 50' at line 1

      Comment

      • zorgi
        Recognized Expert Contributor
        • Mar 2008
        • 431

        #4


        Single-table syntax:
        Code:
        UPDATE [LOW_PRIORITY] [IGNORE] table_reference
            SET col_name1={expr1|DEFAULT} [, col_name2={expr2|DEFAULT}] ...
            [WHERE where_condition]
            [ORDER BY ...]
            [LIMIT row_count]
        You can use LIMIT row_count to restrict the scope of the UPDATE. A LIMIT clause is a rows-matched restriction. The statement stops as soon as it has found row_count rows that satisfy the WHERE clause, whether or not they actually were changed.

        If I understood you correctly (and I am not sure I have)

        Originally posted by canabatz
        i need update the results from the first 50 rows.
        Than LIMIT 50 will do exactly what you need.

        Comment

        • canabatz
          New Member
          • Oct 2008
          • 155

          #5
          can i do something like this:

          Code:
          $sql_update_bids11111="select * form `bidding_details` where (update bidding_details set sortbid = '0', rank = '0' where `bid_id`='$bid_id' and sortbid = '1') limit 0, 50 ";
          thanx

          Comment

          • Markus
            Recognized Expert Expert
            • Jun 2007
            • 6092

            #6
            Where clause syntax looks like: WHERE x = 1 AND x = 2 AND x = 3 ...

            You should be reading the MySQL manual for these questions as they're well covered.

            Comment

            • canabatz
              New Member
              • Oct 2008
              • 155

              #7
              i try and try but cant figure this out!!

              please help!

              this is the code i have:

              Code:
              $query909 = mysql_query("SELECT * FROM `bidding_details` where `bid_id`='$bid_id' and `sortbid` = '1' order by bid_price asc limit 50") or die(mysql_error());
              $last = '';
              $cubid = 0;
              $remove_bid_count = 0;
              while($line = mysql_fetch_assoc($query909)) {
                if($last == $line['username']){ 
                $cubid++;
                $bid_position[$cubid] = $line['bid_price'];
              	} //end of if 
                else {
                  $last = $line['username'];
                  $cubid = 1;
                  $remove_bid_count = 1;
                  $bid_position[$cubid] = $line['bid_price'] ;
                }
                if($cubid > 3) { 
              $remove_bid = $bid_position[$remove_bid_count];
              $sql_update_bids11111="update bidding_details set sortbid = '0', rank = '0' where `bid_id`='$bid_id' and sortbid = '1' and `bid_price`='$remove_bid'";
              mysql_query($sql_update_bids11111)or die(mysql_error());
              
              $remove_bid_count++;
               }
              }
              the problem is if i got 70 rows ,the code starting from the last row and go up 50 rows and not effecting the first 20 rows ,i want the code to effect only the 50 rows ,can some one direct me to the right way!!

              thanx

              Comment

              • zorgi
                Recognized Expert Contributor
                • Mar 2008
                • 431

                #8
                Are you trying to update only selected rows?

                Comment

                • canabatz
                  New Member
                  • Oct 2008
                  • 155

                  #9
                  im updating only one record from the total rows ,but i need the update to look only in the first 50 rows ,not to start from the last row and go up 50!

                  thanx

                  Comment

                  • Markus
                    Recognized Expert Expert
                    • Jun 2007
                    • 6092

                    #10
                    I'm afraid I cannot understand your problem. Please try to explain better.

                    Comment

                    • zorgi
                      Recognized Expert Contributor
                      • Mar 2008
                      • 431

                      #11
                      Originally posted by Markus
                      I'm afraid I cannot understand your problem. Please try to explain better.
                      Same here. Reading it over and over again but don't understand.

                      Comment

                      • canabatz
                        New Member
                        • Oct 2008
                        • 155

                        #12
                        ok ,i give example!

                        i got 80 rows

                        i want to select only the first 50 rows ,i want my update code to look only
                        at the first 50 rows ,if it finds the result it looks for ,then he will update that row!

                        bid_price is going from high price to low price ,my select query is bid_price ASC
                        and i put it in LIMIT 50 ,but it is not starting from row 50 ,it's starting from row 80, row 80 is the lower price!

                        what i need is the query to start from the lower price in row 50!!

                        i hope im better in explaining now!

                        my english is not the best ,sorry!! :)

                        thanx

                        Comment

                        • zorgi
                          Recognized Expert Contributor
                          • Mar 2008
                          • 431

                          #13
                          Originally posted by canabatz
                          ok ,i give example!

                          i got 80 rows

                          i want to select only the first 50 rows ,i want my update code to look only
                          at the first 50 rows ,if it finds the result it looks for ,then he will update that row!
                          So you are updating only within selected rows. You can do that by storing selected rows Id's and than updating with where clause of your SQL command like this:

                          Code:
                           WHERE id IN ($id[0], $id[1], .....)

                          Comment

                          • canabatz
                            New Member
                            • Oct 2008
                            • 155

                            #14
                            can you please show example on this row how i do that:
                            Code:
                            SELECT * FROM `bidding_details` where `bid_id`='$bid_id' and `sortbid` = '1' order by bid_price asc limit 50
                            im kind of new to php!

                            thanx

                            Comment

                            • canabatz
                              New Member
                              • Oct 2008
                              • 155

                              #15
                              some body?
                              please ,i didnt understand the last post ,how to do that?

                              thanx

                              Comment

                              Working...