0

for example, i have a table like this

 book   |  number data  |
-------------------------
 book 1 |       2       |
 book 2 |       3       |
 book 3 |       1       |
 book 4 |       3       |

every number has a name/value:

Good for 1

Okay for 2

Bad for 3

how to transform the numbers and displays them in the form of text? without changing the original data

John Saunders
  • 160,644
  • 26
  • 247
  • 397
  • check http://stackoverflow.com/questions/8763310/how-do-write-if-else-statement-in-a-mysql-query – Pratik Joshi May 25 '15 at 16:22
  • 3
    `$data = array(1 => 'Good', 2 => 'Okay', ...) echo $data[$row['number_data']]`? – Marc B May 25 '15 at 16:23
  • 1
    Unlike forum sites, we don't use "Thanks", or "Any help appreciated", or signatures on [so]. See "[Should 'Hi', 'thanks,' taglines, and salutations be removed from posts?](http://meta.stackexchange.com/questions/2950/should-hi-thanks-taglines-and-salutations-be-removed-from-posts). – John Saunders May 25 '15 at 18:07

2 Answers2

0

You can use an array to get status

$output = Array(1=>"Good",2=>"Okay",3=>"Bad");
echo $output[$numberDate];

OR

Use switch case like this:

$output = ""
switch ($numberDate) {
case 1:
    $output = "Good";
    break;
case 2:
    $output = "Okay";
    break;
case 3:
    $output = "Bad";
    break;
}

echo $output;
A l w a y s S u n n y
  • 36,497
  • 8
  • 60
  • 103
saqibahmad
  • 962
  • 1
  • 9
  • 18
-1
 if ($number == 1) {
    echo "Good";
} elseif ($number == 2) {
  echo "Okay";
} else {
   echo "Bad";
}

Don't use a switch statement, they tend to be slower.

OllyBarca
  • 1,501
  • 1
  • 18
  • 35
  • Please read this for performance: http://stackoverflow.com/questions/2158759/case-vs-if-else-if-which-is-more-efficient, always add references when you try do a statement for performance – saqibahmad May 25 '15 at 16:33
  • In my experience, switch statements tend to run slower. – OllyBarca May 25 '15 at 16:34