0

So here's my code for the dynamic table in Dreamweaver

SELECT diagnose.Service_id, 
IF (diagnose.Type_id = '1',('บันทึกระบบกระดูกและกล้ามเนื้อ'), ('บันทึกแล้ว')) as Diagnose
FROM diagnose 

So the problem is how do I use the ELSE IF option if the diagnose.Type_id = 2 and so on?

1
  • What use CASE instead? Commented Jan 20, 2018 at 12:38

2 Answers 2

1

To be honest, you should have this information in a reference table. I would expect the code to look more like:

SELECT d.Service_id, t.type as diagnoses_type
FROM diagnose d JOIN
     Types t
     ON d.Type_id = t.Type_id;

If you don't have such a reference table, you should build one.

Sign up to request clarification or add additional context in comments.

2 Comments

Do you mean the Type table?
@JoshuaJohn . . . Yes. Types (in this example) would be the reference table for types.
0

You should use CASE for this, see MySQL on CASE:

SELECT diagnose.Service_id,
    (CASE diagnose.Type_id 
    WHEN 1 THEN 'lorum'
    WHEN 2 THEN 'ipsum'
    END) as Diagnose 
FROM diagnose

An alternative notation for CASE, that gives you more freedom, is:

SELECT diagnose.Service_id,
    (CASE  
        WHEN diagnose.Type_id=1 THEN 'lorum'
        WHEN diagnose.Type_id=2 THEN 'ipsum'
    END) as Diagnose 
FROM diagnose

6 Comments

Is this possible? (CASE diagnose.Type_id WHEN 1 THEN 'lorum','saved' WHEN 2 THEN 'ipsum','saved' END) as Diagnose FROM diagnose
You can in any case not assign 2 values to a single column, as Diagnose will be a column after all. So then you could either make it a single string with some delimeter that you in further processing split, or you do this twice.
can i use two CASE in one statement?
Yeah sure: CASE WHEN 1=1 THEN 1 ELSE 2 END as Diagnose, CASE WHEN 2=1 THEN 1 ELSE 2 END as Saved.
ahhh i see but how will i make the word change for example each of the type id will direct to a different submit page because of the types for example 'CASE WHEN diagnose.Type_id=1 then 'save' ELSE '-' END' type 1 refers to nervous system submit page which is the nervous table and is a foreign key to the diagnose table
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.