LIMIT problem!

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

    LIMIT problem!

    i got this code:

    Code:
    $sql_f="SELECT reg_id, count(bid_price) as cnt, min(bid_price) as low FROM `bidding_details` where bid_id='$bid_id' and sortbid = '1' group by reg_id HAVING COUNT(reg_id) > 9  limit 50";
    $results=mysql_query($sql_f)or die(mysql_error());
    $row = mysql_fetch_assoc($results);
    $num = $row['low'];
    $cnt = $row['cnt'];
    
    if($cnt > 9) {
    
    $sql_u="update bidding_details set sortbid = '0' ,rank = '0' where bid_id='$bid_id' and bid_price='$num'";
    mysql_query($sql_u)or die(mysql_error());
    
      }
    what im trying to do is find if a user got over 9 rows in the query result!
    if he got 10 ,the lowest bid is updated!

    my problem is that the limit is not working!

    the problem is that if i got over 50 rows ,lets say 70 rows and the user got 7 rows in the first 50 rows , and 3 more in the other 20 rows then the lowest bid is
    updating too!

    i dont understand why the limit is not working!

    thanx in advanced!!!
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    #2
    Code:
    $sql_f="SELECT reg_id, count(bid_price) as cnt, min(bid_price) as low 
    FROM `bidding_details` 
    where bid_id='$bid_id' and sortbid = '1' 
    group by reg_id 
    HAVING COUNT(reg_id) > 9  limit 50";
    I might be wrong here but LIMIT doesn't really work with GROUP BY.
    It is used to filter the number of results returned, usually based on the ORDER BY clause.
    You may have to re-think the query possibly using a sub-query with a LIMIT clause

    Comment

    • canabatz
      New Member
      • Oct 2008
      • 155

      #3
      there is a way to combine the two querys?

      to make them one!

      Comment

      Working...