แปลงค่าตัวเลขในดาต้าเบส ให้แสดงเป็นตัวหนังสือยังไงค่ะ PHP
ใช้ if ก็ได้ครับ ถ้าไม่เยอะ ถ้ามีแค่ 1 กับ 2
Code (PHP)
$a = $_REQUEST['id'];
if ($a==1){
echo "ทั่วไป";
}else if ($a==2) {
echo "เฉพาะทาง";
}
Date :
2014-06-18 09:31:05
By :
deawx
error อะไรมั้ยครับ?
Code (PHP)
<?php
include ('connect.php');
$sql = "select * from question,section where question.em_id = '".$_SESSION['em_id']."' and question.q_section = section.s_id";
$rs = mysql_query($sql) or die(mysql_error());
while($row = mysql_fetch_array($rs)) {
$category = $row['q_category'];
if($category == 1){
echo "ทั่วไป";
}else if($category == 2){
echo "เฉพาะทาง";
}
echo "<tr >";
echo "<td align='center'> ". $row['s_name'] ." </td>";
echo "<td align='center'>".$row['q_category']."</td>";
echo "<td align='center'>".$row['q_quest']."</td>";
echo "<td align='center'>".$row['q_ans']."</td>";
echo "<td align='center'><a href='edit_part.php?p_id=$row[p_id]&l_id=$row[l_id]'><img src = 'image/pencil.png' width='30' height='30'></a></td>";
echo "</tr>";
}
?>
Date :
2014-06-18 10:27:04
By :
Manussawin
หรือ อีกวิธีนึง ครับ
sql-case-when
Date :
2014-06-18 10:30:40
By :
Manussawin
Code (PHP)
<?php
include ('connect.php');
$sql = "select * from question,section where question.em_id = '".$_SESSION['em_id']."' and question.q_section = section.s_id";
$rs = mysql_query($sql) or die(mysql_error());
while($row = mysql_fetch_array($rs)) {
$category = $row['q_category'];
$qname = "";
if($category == 1){
$qname = "ทั่วไป";
}else if($category == 2){
$qname = "เฉพาะทาง";
}
echo "<tr >";
echo "<td align='center'> ". $row['s_name'] ." </td>";
echo "<td align='center'>".$qname."</td>";
echo "<td align='center'>".$row['q_quest']."</td>";
echo "<td align='center'>".$row['q_ans']."</td>";
echo "<td align='center'><a href='edit_part.php?p_id=$row[p_id]&l_id=$row[l_id]'><img src = 'image/pencil.png' width='30' height='30'></a></td>";
echo "</tr>";
}
?>
Date :
2014-06-18 11:08:37
By :
Manussawin
Date :
2014-06-18 11:26:03
By :
Manussawin
ประวัติการแก้ไข 2014-06-18 11:43:08
Date :
2014-06-18 11:41:34
By :
Alan
Load balance : Server 01