introduction screenshots faq forum blog modules components download
Please use the search function and/or read the FAQ first.

Go to Topic: PreviousNext
Go to: Message ListNew TopicSearchLog InPrint View

Simple blocks of code ?



Posted by: Yikkes
August 12, 2008 03:29PM
Hi Folks,

I wonder if sombody could be kind enough to help me with the following three blocks of code?

I've loaded EasyPHP and got the shell of my little system working.

The first block of code works but the syntax of the second two don't.

Are there any really obvious mistakes that I've overlooked ?

In block two I'm simply reading a field from a table and using inputted Gender but although the data is OK the programme is falling thru' to the 'N/A'. Is there something obvious with the 'When/And' clause that I'm missing?

In block three it's simple 'When' clause but I need to concatenate the results. Again anything obviously wrong about the '&' statement ?

I'd really appreciate any pointers, NOT least a pointer to the best PHP SQL Programmers' Guide online or printed.

Thanks.

HAMISH.


BLOCK I:-

SELECT CASE WHEN SUBSTRING(`data`.`t`, 1, 2) = 'BS' THEN 'Inspirational Doer '
WHEN SUBSTRING(`data`.`t`, 1, 2) = 'UV' THEN 'Pratical Planner '
WHEN SUBSTRING(`data`.`t`, 1, 2) = 'HF' THEN 'Theorising Discusser '
WHEN SUBSTRING(`data`.`t`, 1, 2) = 'DO' THEN 'Emotive Doer '
WHEN SUBSTRING(`data`.`t`, 1, 2) = 'MF' THEN 'Inspirational Planner '
WHEN SUBSTRING(`data`.`t`, 1, 2) = 'WJ' THEN 'Practical Discusser '
WHEN SUBSTRING(`data`.`t`, 1, 2) = 'MJ' THEN 'Theorising Doer '
WHEN SUBSTRING(`data`.`t`, 1, 2) = 'TD' THEN 'Emotive Planner '
WHEN SUBSTRING(`data`.`t`, 1, 2) = 'TH' THEN 'Inspirational Discusser '
WHEN SUBSTRING(`data`.`t`, 1, 2) = 'DQ' THEN 'Practical Doer '
WHEN SUBSTRING(`data`.`t`, 1, 2) = 'BR' THEN 'Theorising Planner '
WHEN SUBSTRING(`data`.`t`, 1, 2) = 'RK' THEN 'Emotive Discusser '
ELSE 'N/A' END as output

- Show quoted text -


BLOCK II:-

SELECT CASE WHEN SUBSTRING(`data`.`d`, 1, 4) = 'WJOU' And GENDER = 'M' THEN 'Contemplative '
WHEN SUBSTRING(`data`.`d`, 1, 4) = 'OJOU' And GENDER = 'M' THEN 'Neither especially Contemplative nor especially Outgoing '
WHEN SUBSTRING(`data`.`d`, 1, 4) = 'WFYU' And GENDER = 'M' THEN 'Very Outgoing '
WHEN SUBSTRING(`data`.`d`, 1, 4) = 'OFYU' And GENDER = 'M' THEN 'Outgoing '
WHEN SUBSTRING(`data`.`d`, 1, 4) = 'WJOU' And GENDER = 'F' THEN 'Very Contemplative '
WHEN SUBSTRING(`data`.`d`, 1, 4) = 'OJOU' And GENDER = 'F' THEN 'Contemplative '
WHEN SUBSTRING(`data`.`d`, 1, 4) = 'WFYU' And GENDER = 'F' THEN 'Neither especially Contemplative nor especially Outgoing '
WHEN SUBSTRING(`data`.`d`, 1, 4) = 'OFYU' And GENDER = 'F' THEN 'Outgoing '
ELSE 'N/A' END as output

- Show quoted text -


BLOCK III:-

SELECT CASE WHEN SUBSTRING(`data`.`m`, 1, 2) = "BM" THEN OVERALL_BFMETHOD= "All Methods " & OVERALL_BFMETHOD
WHEN SUBSTRING(`data`.`m`, 1, 2) = "DB" THEN OVERALL_BFMETHOD= "Doer " & OVERALL_BFMETHOD
WHEN SUBSTRING(`data`.`m`, 1, 2) = "GY" THEN OVERALL_BFMETHOD= "Planner " & OVERALL_BFMETHOD
WHEN SUBSTRING(`data`.`m`, 1, 2) = "NV" THEN OVERALL_BFMETHOD= "Discusser " & OVERALL_BFMETHOD
WHEN SUBSTRING(`data`.`m`, 1, 2) = "DB" THEN OVERALL_BFMETHOD= "Doer " & OVERALL_BFMETHOD
WHEN SUBSTRING(`data`.`m`, 1, 2) = "GY" THEN OVERALL_BFMETHOD= "Planner " & OVERALL_BFMETHOD
WHEN SUBSTRING(`data`.`m`, 1, 2) = "NV" THEN OVERALL_BFMETHOD= "Discusser " & OVERALL_BFMETHOD
ELSE 'N/A' END OVERALL_BFMETHOD as output

- Show quoted text -
Options: ReplyQuote
Posted by: Yikkes
August 15, 2008 12:09PM
Where do I find the MySQL speciqlised forum ?

Thanks for you help so far.

H.
Options: ReplyQuote
Posted by: mega-squall
August 18, 2008 02:20PM
You can try MySQL official forums at [forums.mysql.com]
You can also search for "mysql forums" in your favorite search engine.

---
mega-squall
Options: ReplyQuote
Posted by: phpcore
December 16, 2008 02:01PM
why tryin to do something hardly with mysql that could be very simple by php coding ?
Options: ReplyQuote


Go to: Message ListSearchLog In
Your Name: 
Your Email: 
Subject: 
Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.