Jump to content

Recommended Posts

ok , i got this code for limiting users for max 9 records in the first 50 rows .

 

i want to my code  to check only in the first 50 rows .

 

now if i got lets say 70 rows ,the SELECT limit is not working , it starting from row 70 ,and i need it to look only in the 50 first rows.

 

if you got 10 rows from the same user ,the last record will be updated to be bad! (over the rule)

 

my quastion is how can i force this limit to look only in the first 50 rows ,so if a user have 9 rows in the first 50 is ok ,and if he got more rows

from 50 to 70 it's ok then!

 

$query = mysql_query("SELECT reg_id FROM `bidding_details` where bid_id='$bid_id' and sortbid = '1' and username='$username' limit 50") or die(mysql_error());
$last = '';
$count = 0;
while($line = mysql_fetch_assoc($query)) {
  if($last == $line['reg_id']) $count++; 
  else {
    $last = $line['reg_id'];
    $count = 1;
  }
  if($count > 9) {
$sql_delete="update bidding_details set sortbid = '0' ,rank = '0' where bid_id='$bid_id' and username='$username' and  sortbid = '1' order by bid_price asc limit 1";
mysql_query($sql_delete)or die(mysql_error());
  }
} 

Link to comment
https://forums.phpfreaks.com/topic/180400-limit-in-update-any-way-to-do-that/
Share on other sites

what exactly do you want this part of the script to do?

 

get the first 50 rows... then you should order them by price

"ORDER BY bid_price DESC" ??

 

then you want to check if a user has more than 9 bids in those 50?

and if so make the smallest bids false..?

 

whats your primary key for the bids??

$query = mysql_query("SELECT id, reg_id FROM `bidding_details` where bid_id='$bid_id' and sortbid = '1' and username='$username' ORDER BY bid_price DESC") or die(mysql_error());
$last = '';
$count = 0;
while($line = mysql_fetch_assoc($query)) {
  if($last == $line['reg_id']) $count++;
  else {
    $last = $line['reg_id'];
    $count = 1;
  }
  if($count > 9) {
$id = $line['id'];
$sql_delete="update bidding_details set sortbid = '0', rank = '0' where id = '$id'";
mysql_query($sql_delete)or die(mysql_error());
  }
} 

 

there would be much cleaner ways to do it, but that should work?

you might be better off just deleting that row? rather than making it "false"..

i.e.

$sql_delete="DELETE FROM bidding_details WHERE id = '$id'";

 

EDIT: i didn't put in a limit 50 on the select because this script will only delete rows if a user has more than 9 entries in that auction, and they should be deleted regardless of if they're in the top 50 or top 200....

thanx man for your replays!

 

but it's still updating over 50 rows , i need only in the 50 rows to check if the user got over 9 records!

 

your code is working the same as my code!

 

i most limit the code for the first 50 rows!

 

if a user got 9 records in the first 50 thats ok ,if he got more records over the 50 rows thats ok to have!

 

thanx again

add a limit to joels query?

$query = mysql_query("SELECT id, reg_id FROM `bidding_details` where bid_id='$bid_id' and sortbid = '1' and username='$username' ORDER BY bid_price DESC LIMIT 50");

 

I still don't see why your doing this, but I don't care, so whatever

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.