Jump to content

LIMIT problem!


canabatz

Recommended Posts

can some on e please please tell me why my limit is not working!

im trying to get result only from 50 rows ,why the limit is not working!

 

here is my 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());

  }

 

 

thanx in advanced!

Link to comment
Share on other sites

Maybe this will help clear things up:

 

<?php

$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());

echo mysql_num_rows($results) . " rows returned <br />";

while ($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());
}
}

Link to comment
Share on other sites

Have you tried removing the limit clause to check that you're returning +50 rows?

 

I'm not entirely sure what you mean with your question but to loop through a record set, you actually need to use a loop..

 

while ($row = mysql_fetch_assoc($results))
{
    // ...
}

 

Edit: which is what flyhoney's code does.

Link to comment
Share on other sites

thanx flyhoney.

 

but it is the same ,like the limit is not working!

 

i want to check if the user got over 9 records in the first 50 rows ,not over that!

 

you code is working on the first 50 rows very well!

but when im inserting new record that need to be for example in row 60 ,then this record is updated!

 

any clue?

 

thanx all

Link to comment
Share on other sites

there is no way to do that?

 

what im doing is selecting one record from 50 and call it $num ,what i want to update is only $num

if there is no more then 9 rows in the LIMIT 50  from same user why go to other rows?

 

this is what i cannot understand!

 

maybe some other way to pass this ?

 

thanx

Link to comment
Share on other sites

Your UPDATE statement updates every row in the database.  I don't think there is a way to LIMIT an UPDATE statement.  LIMITS are only for SELECTs.

 

you can use LIMIT within an SQL UPDATE command.  not on INSERT, though.

 

OP:  i'm not sure if you understand how the LIMIT syntax works exactly.  LIMIT 50 in your query will only allow for 50 records to be returned (assuming there are 50 records matching your query), and no more.  that is all.

 

if you loop your results and count them, you will have 50 results returned (maybe less, but no more).

 

your logic is well off.  just look at all the conditions in your first query compared to your second query.  of course there will be differences.

 

EDIT: in all fairness, i don't really understand 100% what it is you're trying to do.  i'm sure it's not too complicated, i just don't have the time to try and figure out all the details of your problem.  you need to better explain your issues.

Link to comment
Share on other sites

Hi mrMarcus,

 

i got auction site and there is rules ,the rule is :

 

user cannot have more then 9 records in first 50 results!

 

there is a table in my site that showing the users all records  and the bid_price is hidden

 

the results display like that the Highes bid_price is at the top of the result ,im getting the result with BID_PRICE DESC

 

the results are in pagination ,50 rows every page ,so the rule is only on page 1!

 

to win the auction you need to be first in the table ,there is max bid allowed ,so you cannot over bid!

 

so when user got 9 records all ready and he is not at the top with the highst bid ,he is trying

to bid more to have more chance to win!

 

and if is bidding more then what i need is that is lowest bid will be updated to SORTBID = 0

 

(SORTBID = 0 ) = burnt bid!

 

i hope is better my explanation now!!

 

thanx

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.