If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > If-then-else

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-01-06, 03:05
raddy59 raddy59 is offline
Registered User
 
Join Date: Sep 2006
Posts: 2
If-then-else

I am new to MySQL and am ploughing through.
A question I am sure everyone else can answer without trying:

How do I code an SQL statement to do this (if I can?):

Select the required account

IF the account is found

IF the balance is less than $100
DO y
ELSE
DO z
ENDIF

ENDDO

And how would this interact with my website/PHP? Checking '$result' would show mw what? Or would I code 2 seperate SQL statements from my PHP script?

Hope I am not showing myself to be too ignorant here!
Reply With Quote
  #2 (permalink)  
Old 09-01-06, 10:35
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
when you select the account from the table, you can use a CASE expression to return something if the balance is < 100, and something else if the balance is >= 100

however, if you want to do something, then this will have to be done with php
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 09-02-06, 02:53
raddy59 raddy59 is offline
Registered User
 
Join Date: Sep 2006
Posts: 2
Thanks r937
just to get this right:
In my PHP script set up a query to check for the record's existence on the table
If I find it, I do the checking in the PHP script on the balance
Depending on the balance I perform the appropriate action - is that correct.

What do I do if somebody else comes along and updates the balance while I am checking it - or is this beyond ths scope of this thread?
Reply With Quote
  #4 (permalink)  
Old 09-02-06, 04:14
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
yes, i think you have to lock the record

just what is this "appropriate action" that needs doing?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On