conditional display

Questionsconditional display
anuj asked 8 years ago

hi,
i want to use condition for display data in column from MY TABLE .And in DB value is 0,1,2,3, and i want to display like AB,AJ,RF,COD how to display like this in column,sir
if value 0 display AB,if value is 1 display AJ,like this in column…

thanks sir..

3 Answers
Abu Ghufran answered 8 years ago

You can use IF condition in select_command query.
IF(field=0,"AB", IF (field=1, "AJ", IF (field=2, "RF", "COD"))) as field

anuj answered 8 years ago

$g->select_command = "SELECT DISTINCT tblorders.OrderId,tblorders.userId, tbluser.fullName,tblorders.Totalinvoice,tblorders.PaymentStatus,tblorders.SubTotal
FROM tbluser
INNER JOIN tblorders ON tbluser.userId= tblorders.userId IF(PaymentStatus=0,"due", IF (PaymentStatus=1, "AJ", IF (PaymentStatus=2, "RF", "COD")))";

its not working …same value is displaying..

Abu Ghufran answered 8 years ago

IF clause is part of column selection in query.
It would be something like:

$g->select_command = "SELECT DISTINCT tblorders.OrderId,tblorders.userId, tbluser.fullName,tblorders.Totalinvoice,
IF(tblorders.PaymentStatus=0,"due", IF (tblorders.PaymentStatus=1, "AJ", IF (tblorders.PaymentStatus=2, "RF", "COD")))
as PaymentStatus
,tblorders.SubTotal
FROM tbluser
INNER JOIN tblorders ON tbluser.userId= tblorders.userId";

If issue persist, refer mysql query manual for IF clause use.

Your Answer

3 + 13 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?