List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:August 27 1999 10:30pm
Subject:Re: A little code help.
View as plain text  
At 5:30 PM -0500 8/27/99, Micheal Mc Evoy wrote:
>On Fri, 27 Aug 1999, Z Mehta wrote:
>
>>Could someone help me with a some code.  I am working with only one
>>table in my database and I have a datestamp column called due_date.
>>What I would like  to do is select a row with the first instance of
>>'raw' in column "Status".  I then would like to change the
>>"Status"column to 'idle'.
>>
>>$query = "SELECT * FROM queue
>>   where status='raw' ORDER BY due_date ASC LIMIT 1";
>>$result = mysql_query($query);
>>$result = "UPDATE queue SET Status='idle'
>>   where status='raw'";
>>
>>  Thanks Zubin
>
>use DBI;
>use strict;
>
>my $dbh = DBI->connect($database, $user, $pword, {RaiseError => 1});
>my $sth = $dbh->do("UPDATE queue SET status = 'idle' WHERE status =
>'raw'");
>$dbh->disconnect;

That was my first thought, too, but I wonder.  The way the original
question is phrased implies there may be more than one row with a
status of 'raw'.  If so, the update will update them all, which is
not (I think) what is intended.

I think that to solve this problem, there will have to be some
unique value in each row.  Then when you select the first row with
a status of 'raw', pull out the unique value, and perform the update
using the unique value.  Something like this:


SELECT uniq_col FROM queue WHERE status = 'raw' ORDER By due_date LIMIT 1
UPDATE queue SET status = 'idle' WHERE uniq_col = value-from-select-query

--
Paul DuBois, paul@stripped
Northern League Chronicles: http://www.snake.net/nl/
Thread
A little code help.Z Mehta27 Aug
  • Re: A little code help.Micheal Mc Evoy28 Aug
  • Re: A little code help.Paul DuBois28 Aug
  • Re: A little code help.Z Mehta28 Aug
    • Re: A little code help.Paul DuBois28 Aug
    • Re: A little code help.Paul DuBois28 Aug
  • Re: A little code help.Z Mehta28 Aug