Solved

Why is query sometimes not executing

Posted on 2011-02-22
13
391 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
 
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
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…

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now