Jump to content

[SOLVED] Query returns old value


n14charlie

Recommended Posts

I want to increment a value in the table (which is 0 at the begining) but everytime I do query on the table

it returns 0 even after I incremented it.

 

$query = mysql_query(" SELECT * from session".$session."_".$username." WHERE Auction_Num = $highest_Num" ,$connection);  
              $result = mysql_fetch_array($query);
               $bid_hover_num = $result['Bid_Hover_Windows'];
               $bid_hover_num = (int)$bid_hover_num + 2;
              mysql_query(" UPDATE session".$session."_".$username." SET Bid_Hover_Windows = $bid_hover_num  
                    WHERE Auction_Num = $highest_num" ,$connection); 

 

the value just stays "2" all the time which leads me to thing Im getting "0" from the table all the time.

I replaced the "+2" with a "+rand(1,1000)" and it just replaces the zero with the random value.

 

 

Link to comment
Share on other sites

Well, why don't you try debugging your update query? Or, indeed, echoing the value from the database before you do anything to it? I'll direct you to the database errors section of a tutorial i wrote: http://www.phpfreaks.com/tutorial/debugging-a-beginners-guide

 

On the other hand, you don't need to select something from a database in order to increment it. You can do the following instead:

 

UPDATE yourtable SET foobar=foobar + 2 WHERE ...

Link to comment
Share on other sites

Well, why don't you try debugging your update query? Or, indeed, echoing the value from the database before you do anything to it? I'll direct you to the database errors section of a tutorial i wrote: http://www.phpfreaks.com/tutorial/debugging-a-beginners-guide

 

On the other hand, you don't need to select something from a database in order to increment it. You can do the following instead:

 

UPDATE yourtable SET foobar=foobar + 2 WHERE ...

 

well that worked, I have no idea why my way was wrong though :/

thank you for the help

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.