?
Solved

Why is query sometimes not executing

Posted on 2011-02-22
13
Medium Priority
?
399 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Interactive Way of Training for the AWS CSA Exam

An interactive way of learning that will help you visualize core concepts so that you can be more effective when taking your AWS certification exam.  Built for students by a student to help them understand the concepts that they are being taught.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Recently I was talking with Tim Sharp, one of my colleagues from our Technical Account Manager team about MongoDB’s scalability. While doing some quick training with some of the Percona team, Tim brought something to my attention...
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
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…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

741 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