Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9004667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:56:50+00:00 2026-06-16T00:56:50+00:00

In a table in my database, I have a column that stores status values

  • 0

In a table in my database, I have a column that stores status values for posts. So if a post is published, it’s 0, draft = 1, if it’s yet to be looked at by a moderator – it’s 2, if it’s deleted – it’s 3

So table looks like:

postid | status
----------------
  1        0
  2        1
  3        2

I need to display an icon for each post based on it’s status. Can I do something like this in a sql query itself instead of writing more php code:

Eg:

select postid as pId, status as status (if status = 0 {status = '<img src="published.png"'} elseif if status =1 {status = '<img src="draft.png"'}

I hope you got the idea. (The above sql statement is just for example)
Can something like this be done.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T00:56:51+00:00Added an answer on June 16, 2026 at 12:56 am

    You can use the CASE expression, like so:

    select 
      postid as pId, 
      CASE 
        WHEN status = 0 THEN '<img src="published.png"'
        ELSE '<img src="draft.png"' 
      END AS status
    FROM table
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database table column that stores urls of a persons website. This
I have a database table with a column called 'symbol', that is unique via
I have an SQL Server 2008 database with a table that has a column
i have a large mysql database table in which one column contains values ranging
I have a table in a SQLite database where a column stores file mtimes
I have a SQL Server database with a table that has a column that
I need a status column that will have about a dozen possible values. Is
I have a certain column in a table that stores a number. I want
I have one problem... There is a table in my MySQL database that stores
I have several database tables that just contain a single column and very few

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.