Connecting Tech Pros Worldwide Forums | Help | Site Map

update the rows the query found

Familiar Sight
 
Join Date: Oct 2008
Posts: 143
#1: Aug 23 '09
i got this query that finds me the duplicate rows

Expand|Select|Wrap|Line Numbers
  1. $duplicates = mysql_query("SELECT bid_price, count(*) FROM bidding_details where bid_id= '1128' and sortbid = '1' GROUP BY bid_price having count(*) > 1");
  2. $count = mysql_num_rows($duplicates);
  3. if ($count > 0) {
  4.     while ($row = mysql_fetch_assoc($duplicates)) {
  5.         $bid_price = $row["bid_price"];
  6.     }
  7.     echo $count;
  8.  
  9.     mysql_free_result($duplicates);
  10. }
what i need is to update those rows ,i want to update those rows to be SORTBID='0'

please help ,thanx

Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,949
#2: Aug 23 '09

re: update the rows the query found


Well, using the same WHERE clause, just do an UPDATE instead of a SELECT.
Familiar Sight
 
Join Date: Oct 2008
Posts: 143
#3: Aug 23 '09

re: update the rows the query found


sorry for not trying it ,im afraid to do something wrong :)?
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. include('conn.php');
  3. $duplicates = mysql_query("SELECT bid_price, count(*) FROM bidding_details where bid_id= '1128' and sortbid = '1' GROUP BY bid_price having count(*) > 1");
  4. $count = mysql_num_rows($duplicates);
  5. if ($count > 0) {
  6.     while ($row = mysql_fetch_assoc($duplicates)) {
  7.         $bid_price = $row["bid_price"];
  8.  
  9.     $duplicates1 = mysql_query("UPDATE bidding_details SET sortbid='0' where bid_id= '1128' and sortbid = '1' GROUP BY bid_price having count(*) > 1");
  10.  
  11.     }
  12.  
  13.     mysql_free_result($duplicates);
  14. }
  15. ?>
thanx
Familiar Sight
 
Join Date: Oct 2008
Posts: 143
#4: Aug 23 '09

re: update the rows the query found


is it going to work?
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,949
#5: Aug 23 '09

re: update the rows the query found


You don't need the while loop, just run the query; because you're using a WHERE clause, all affected rows will be updated by the query.
Familiar Sight
 
Join Date: Oct 2008
Posts: 143
#6: Aug 23 '09

re: update the rows the query found


Expand|Select|Wrap|Line Numbers
  1. $duplicates = mysql_query("SELECT bid_price, count(*) FROM bidding_details where bid_id= '1128' and sortbid = '1' GROUP BY bid_price having count(*) > 1");
  2. $count = mysql_num_rows($duplicates);
  3. if ($count > 0) {
  4.     $duplicates1 = mysql_query("UPDATE bidding_details SET sortbid='0' where bid_id= '1128' and sortbid = '1' GROUP BY bid_price having count(*) > 1");
  5.     }
Familiar Sight
 
Join Date: Oct 2008
Posts: 143
#7: Aug 23 '09

re: update the rows the query found


can you explain for me please ,what i need?

can i do it with one row of a code?


please ,im not so good in php ,im learning from examples !

thank you
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,949
#8: Aug 23 '09

re: update the rows the query found


That _should_ work.

Gives me 10 minutes (just got in from doing some work with my pa, gotta cool down) and I'll explain it for you.

Mark.
Reply