Solved

Why is query sometimes not executing

Posted on 2011-02-22
13
393 Views
Last Modified: 2012-05-11
Hi guys

I have this query

$update = "
            UPDATE Users t1 SET
                NewMail =
                    CASE
                        WHEN (NewMail=0 OR NewMail IS NULL) THEN 1
                        ELSE NewMail + 1
                    END
            WHERE
                UserId = $rUserId
            LIMIT 1
        ";
        mysql_query($update);

it is executed with other queries..

IT DOES NOT FAIL.

But sometimes it does not update and the NewMail keeps beeing 0. why is that?
0
Comment
Question by:tim_carter
  • 8
  • 4
13 Comments
 
LVL 15

Expert Comment

by:Aaron Shilo
ID: 34953123
hi

probably becuse you use the LIMIT 1
this means update the last value

change the value to a larger number or remove.
0
 
LVL 1

Author Comment

by:tim_carter
ID: 34953140
It is only 1 user that it should update at this point? why would i run through every record?
0
 
LVL 15

Expert Comment

by:Aaron Shilo
ID: 34953178
just to be clear you need to update only one record at a time ?
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 1

Author Comment

by:tim_carter
ID: 34953358
YES. it is only one user..

like UserId=2


0
 
LVL 15

Expert Comment

by:Aaron Shilo
ID: 34953395
that isent what i asked.

when you use Userid= 2 will you allways retrive only one row from the table?
0
 
LVL 1

Author Comment

by:tim_carter
ID: 34953416
and that is what i need. but sometimes it does not update the NewMail value
0
 
LVL 15

Expert Comment

by:Aaron Shilo
ID: 34953449
hi
when you run this query

select * from Users
                    where NewMail=0 OR NewMail IS NULL
                     and UserId = $rUserId

notice i removed the LIMIT 1

how meny rows come bac ?
0
 
LVL 1

Author Comment

by:tim_carter
ID: 34953484
what has this query to do with what i want?

1st of the query you have done here will return almost anything because you have not encapsulated (newmail)

MY STATEMENT should update 1 user. and if the user has the value 0 or NULL in newmail it should set the value to 1, else it should add to the current value,.
0
 
LVL 20

Expert Comment

by:Muhammad Wasif
ID: 34953485
>>But sometimes it does not update and the NewMail keeps beeing 0. why is that?
Are you sure that $rUserId is not empty during this time? May be query is failing due to some eorr or $rUserId has incorrect value. Use mysql_error() to detec the error and print the query to debug the issue in this way.

mysql_query($update) or die("Error in Query: $update - ". mysql_error());

Open in new window

0
 
LVL 1

Author Comment

by:tim_carter
ID: 34953557
wasifg

I am already doing that in the script..

It does not fail. And it is randomly it happens.
0
 
LVL 1

Author Comment

by:tim_carter
ID: 34953895
Can it have something to do with CASE?
0
 
LVL 1

Accepted Solution

by:
tim_carter earned 0 total points
ID: 35300046
I found out that sometimes my value was less than zero.
0
 
LVL 1

Author Closing Comment

by:tim_carter
ID: 35331365
less than zero. My own error
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question