Search code examples
phphtmlsqlhtml-tabledata-retrieval

fetch sql data using php and show in a html table using different names?


I sava data in sql table as

  • male as 1
  • female as 2

now I want to get that data back to HTML page and print, but data print as 1/2.how I print that data as Male and Female???


Solution

  • If you are using MySQL, you can do it inside SQL statement just like the example below.

    SELECT IF(n_gender = 1, 'male', 'female') AS s_gender 
    FROM   students;