Solved

Why is query sometimes not executing

Posted on 2011-02-22
13
398 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
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

Turn Insights Into Action

You’ve already invested in ITSM tools, chat applications, automation utilities, and more. Fortify these solutions with intelligent communications so you can drive business processes forward.

With xMatters, you'll never miss a beat.

Question has a verified solution.

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

Containers like Docker and Rocket are getting more popular every day. In my conversations with customers, they consistently ask what containers are and how they can use them in their environment. If you’re as curious as most people, read on. . .
Your data is at risk. Probably more today that at any other time in history. There are simply more people with more access to the Web with bad intentions.
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…
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…

691 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