|
|
|
ดึงข้อมูลจาก SQL มาแสดงผลแล้วอยากให้ข้อมูลเปลี่ยนเป็นไอคอนรูป |
|
|
|
|
|
|
|
น่าจะเข้าใจนะคับ
Code (PHP)
<table width="200" border="1">
<tr>
<td>ชื่อ</td>
<td>เพศ</td>
</tr>
<?
$sql = " SELECT name, sex FROM table ";
$qe = mysql_query($sql);
while ($rw = mysql_fetch_array($qe)){
?>
<tr>
<td><?=$rw['name']?></td>
<td><?
if($rw['sex']=='M'){ ชื่อfolder/ชาย.gif
}else{ ชื่อfolder/หญิง.gif}
?>
</td>
</tr>
<? }?>
</table>
|
|
|
|
|
Date :
2011-05-10 18:29:48 |
By :
TEST_CODE |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
คือลองใส่ดูแล้วแต่ก็ยังไม่ได้ครับ ช่วยชี้แนะหน่อยครับว่าผมควรจะใส่ตรงไหน ยังไง
อันนี้ code ต้นฉบับของหน้าที่ผมดึงข้อมูลมาแสดง จาก SQL ครับ
ชื่อฟิลของผมคือ sex มีข้อมูลเป็น "ชาย" และ "หญิง"
Code (PHP)
<?php require_once('Connections/studen.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
mysql_select_db($database_studen, $studen);
$query_Recordset1 = "SELECT * FROM `data`";
$Recordset1 = mysql_query($query_Recordset1, $studen) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<table border="0">
<tr>
<td>sex</td>
<td>name</td>
<td>family</td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $row_Recordset1['sex']; ?></td>
<td><?php echo $row_Recordset1['name']; ?></td>
<td><?php echo $row_Recordset1['family']; ?></td>
</tr>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</table>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>
|
ประวัติการแก้ไข 2011-05-10 23:01:24
|
|
|
|
Date :
2011-05-10 22:55:26 |
By :
puttapon |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
<?php
$male = "ชาย";
$female = "หญิง";
$imgmale = "images/ชื่อ icon ผู้ชาย.jpg";
$imgfemale = "images/ชื่อ icon ผู้หญิง.jpg";
?>
<table border="0">
<tr>
<td>sex</td>
<td>name</td>
<td>family</td>
</tr>
<?php do { ?>
<tr>
<td>
<?php
if($row_Recordset1['sex'] == $male)
{
echo $imgmale;
}
?>
</td>
<td><?php echo $row_Recordset1['name']; ?></td>
<td><?php echo $row_Recordset1['family']; ?></td>
</tr>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</table>
|
|
|
|
|
Date :
2011-05-10 23:10:32 |
By :
prach_kp |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ลองทำดูแล้วครับ
ผู้ชายไม่ยอมแสดงไอคอนชาย แต่กลับแสดงเป็นข้อความที่อยู่ของรูป
ผู้หญิง ไม่มีอะไรเกิดขึ้น
ทำไงอะครับ
|
|
|
|
|
Date :
2011-05-16 19:21:39 |
By :
puttapon |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
<?php require_once('Connections/studen.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
mysql_select_db($database_studen, $studen);
$query_Recordset1 = "SELECT * FROM `data`";
$Recordset1 = mysql_query($query_Recordset1, $studen) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<table border="0">
<tr>
<td>sex</td>
<td>name</td>
<td>family</td>
</tr>
<?php do { ?>
<tr>
<td><?php if($row_Recordset1['sex'] =='ชาย'){ echo "<img src=image/รูปผู้ชาย.jpg>";}else{ echo "<img src=image/รูปผู้หญิง.jpg>";} ?></td>
<td><?php echo $row_Recordset1['name']; ?></td>
<td><?php echo $row_Recordset1['family']; ?></td>
</tr>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</table>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>
|
|
|
|
|
Date :
2011-05-16 20:05:29 |
By :
Dragons_first |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|