|
|
|
ช่วยด้วยคับมือใหม่ ทำยังไงให้ dropdownlist ติดต่อกับฐานข้อมูลอะคับ |
|
|
|
|
|
|
|
กำลังหัดเขียน คือว่าอยากดึงเอาข้อมูลใน Status
คือผมทำให้เป็นตัวเลือกอะคับ
แล้วทำให้มันติดต่อกันอะคับ
นี่คือโค้ดของหน้านี้คับ เขียนมามั่วๆคับ
ที่อยากให้ช่วยคือตรงส่วนของระบบอะคับ
Code (PHP)
<?
session_start();
if($_SESSION['id'] == "")
{
echo "Please Login!";
exit();
}
if($_SESSION['Status'] != "ADMIN")
{
echo "This page for Admin only!";
exit();
}
$hostname = "localhost";
$user = "root";
$password = "123456";
$dbname = "leave";
$tblname = "useradmin";
mysql_connect($hostname,$user,$password)or die("ติดต่อฐานข้อมูลไม่ได้");
mysql_select_db($dbname) or die ("เลือกฐานข้อมูลไม่ได้");
$sql = "select * from $tblname WHERE id = '".$_SESSION['id']."'";
$dbquery = mysql_db_query($dbname,$sql);
?>
<html>
<head>
<title>รายงานการลา</title>
<meta http-equiv="Content-Type" content="text/html; charset=tis-620">
<link href="css/style.css" rel="stylesheet" type="text/css">
</head>
<body bgcolor="#ffffff">
<br>
<div align="center"><br>
<table border="0" cellpadding="0" cellspacing="0" width="945">
<tr>
<td><div align="right"><font color="#993333" size="2"><img src="images/icon_man.gif" width="15" height="15">
<font color="#333333">ยินดีต้อนรับคุณ</font></font><font color="#FF0000" size="2">
<? echo "<u $adminname /u>"; ?> <font color="#333333">เข้าใช้งานในระบบ<br>
<a href="Profiles.php">ข้อมูลส่วนตัว</a> | <a href="Logout.php"><font color="#990000">ออกจากระบบ</font></a></font></font>
</div></td>
</tr>
<tr>
<td><img name="bx_r1_c1" src="images/bx_r1_c1.jpg" width="945" height="28" border="0" alt=""></td>
</tr>
<tr>
<td background="images/bx_r2_c1.jpg"><div align="center">
<table width="99%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><table width="936" border="0" cellspacing="1" cellpadding="1">
<tr>
<td width="150"><div align="center"><a href="AddUser.php"><img src="images/m1.jpg" width="117" height="71" border="0"></a></div></td>
<td width="1"> </td>
<td width="130"><div align="center"><a href="Depart.php"><img src="images/m3.jpg" width="117" height="71" border="0"></a></div></td>
<td width="130"><div align="center"><a href="Leavetype.php"><img src="images/m4.jpg" width="117" height="71" border="0"></a></div></td>
<td width="1"> </td>
<td width="130"><div align="center"><a href="Leavereportperday.php"><img src="images/m6.jpg" width="117" height="71" border="0"></a></div></td>
</tr>
</table></td>
</tr>
<tr>
<td><div align="center"><br>
</div></td>
</tr>
<tr>
<td><img src="images/h1.jpg" width="228" height="32"></td>
</tr>
<tr>
<td><div align="center">
<table width="99%" border="0" align="center" cellpadding="1" cellspacing="1">
<tr>
<td><div align="center">
<table border="0" cellpadding="0" cellspacing="0" width="673">
<!-- fwtable fwsrc="Untitled" fwbase="bxx.jpg" fwstyle="Dreamweaver" fwdocid = "742308039" fwnested="0" -->
<tr>
<td><img src="spacer.gif" width="673" height="1" border="0" alt=""></td>
<td><img src="spacer.gif" width="1" height="1" border="0" alt=""></td>
</tr>
<tr>
<td><img name="bxx_r1_c1" src="images/bxx_r1_c1.jpg" width="673" height="8" border="0" alt=""></td>
<td><img src="spacer.gif" width="1" height="8" border="0" alt=""></td>
</tr>
<tr>
<td background="images/bxx_r2_c1.jpg"> <script language="JavaScript">
function checkprdtype()
{
var prd1 = document.webFormprdtype.productstypename.value;
if( prd1.length ==0)
{
alert("กรุณาใส่ประเภทสินค้าด้วยค่ะ");
document.webFormprdtype.productstypename.focus();
return false;
}
else
return true;
}
</script> <table width="90%" border="0" align="center" cellpadding="1" cellspacing="1">
<form method="post" action="AddUsersave.php" name="webFormprdtype" onSubmit="return checkprdtype()">
<tr bgcolor="#FFFFFF">
<td width="163"> <div align="right"><font size="2">รหัสพนักงาน
:</font></div></td>
<td width="445"><font size="3">
<?
$sql = "select * from $tblname WHERE id = '".$_SESSION['id']."'";
$db_queryr=mysql_db_query($dbname,$sql);
$result_numcode=mysql_fetch_array($db_queryr);
$num_rows_code=mysql_num_rows($db_queryr);
$run_number = $num_rows_code+1;
echo "<input type=text name=userid value='User-$run_number' class=input>";
?>
</font><font size="3">
</font></td>
</tr>
<tr bgcolor="#FFFFFF">
<td> <div align="right"><font size="2">ชื่อพนักงาน
:</font></div></td>
<td><font size="3">
<input name="admin_name" type="text" class="input" id="admin_name" size="40">
</font><font size="3">
</font></td>
</tr>
<tr bgcolor="#FFFFFF">
<td><div align="right"><font size="2">ตำแหน่ง
:</font></div></td>
<td><font size="3">
<input name="position" type="text" class="input" id="position" size="40">
</font><font size="3">
</font></td>
</tr>
<tr bgcolor="#FFFFFF">
<td><div align="right"><font size="2">แผนก/ฝ่าย
:</font></div></td>
<td><select name="departid" class="input" id="departid">
<option selected>แผนก/ฝ่าย</option>
<option value="100">ฝ่ายบุคคล</option>
<option value="200">ฝ่ายผลิต</option>
</select></td>
</tr>
</td>
</tr>
<tr bgcolor="#FFFFFF">
<td><div align="right"><font size="2">รหัสผ่าน
:</font></div></td>
<td><font size="3">
<input name="password" type="password" class="input" id="password" size="20">
</font><font size="3">
</font></td>
</tr>
<tr bgcolor="#FFFFFF">
<td><div align="right"><font size="2">ยืนยันรหัสผ่าน
:</font></div></td>
<td><font size="3">
<input name="repassword" type="password" class="input" id="repassword" size="20">
</font><font size="3">
</font></td>
</tr>
<tr bgcolor="#FFFFFF">
<td><div align="right"><font size="2">ส่วนของระบบ
:</font></div></td>
<td><select name="Status" class="input" id="Status">
<option selected>ส่วนระบบ</option>
<option value="AMIN">Administrator</option>
<option value="ENDORSEE">ผู้อนุมัติการลา</option>
<option value="STAFF">เจ้าหน้าที่</option>
<option value="USER">พนักงานทั่วไปทั่วไป</option>
</select></td>
</tr>
<tr bgcolor="#FFFFFF">
<td> </td>
<td><font size="3">
<input name="submit" type="submit" class="submit" value="เพิ่มข้อมูล" onClick="return confirm ('คุณต้องการบันทึก ใช่ หรือ ไม่? ') ">
</font></td>
</tr>
</form>
</table></td>
<td><img src="spacer.gif" width="1" height="20" border="0" alt=""></td>
</tr>
<tr>
<td><img name="bxx_r3_c1" src="images/bxx_r3_c1.jpg" width="673" height="8" border="0" alt=""></td>
<td><img src="spacer.gif" width="1" height="8" border="0" alt=""></td>
</tr>
</table>
</div></td>
</tr>
<tr>
<td><div align="center">
<table border="0" cellpadding="0" cellspacing="0" width="673">
<!-- fwtable fwsrc="Untitled" fwbase="bxx.jpg" fwstyle="Dreamweaver" fwdocid = "742308039" fwnested="0" -->
<tr>
<td><img src="spacer.gif" width="673" height="1" border="0" alt=""></td>
<td><img src="spacer.gif" width="1" height="1" border="0" alt=""></td>
</tr>
<tr>
<td><img name="bxx_r1_c1" src="images/bxx_r1_c1.jpg" width="673" height="8" border="0" alt=""></td>
<td><img src="spacer.gif" width="1" height="8" border="0" alt=""></td>
</tr>
<tr>
<td background="images/bxx_r2_c1.jpg"> <div align="center">
<table width="94%" border="0" cellspacing="0" cellpadding="0">
<tr class="jobscss">
<td bgcolor="#FFFFFF">
<?
$page = $_GET['page'];
$select_type="select * from $tblname WHERE id = '".$_SESSION['id']."'";
///"select * from useradmin order by id asc";
$query_select=mysql_query($select_type);
$num_rows=mysql_num_rows($query_select);
if($num_rows<1){
echo "<br><br><center><font color=#666666 face=tahoma size=2><b>ยังไม่มีการเพิ่มข้อมูล</b></font></center>";
}else{
$select="select * from $tblname WHERE id = '".$_SESSION['id']."'";
///"select * from useradmin order by id asc";
$q_ry = mysql_query($select);
$num_rows=mysql_num_rows($q_ry);
$pagesize=20;
$rt=$num_rows%$pagesize;
if($rt!=0)
{
$totalpage=floor($num_rows/$pagesize)+1;
}
else
{
$totalpage=floor($num_rows/$pagesize);
$toppic_id=1;
}
if(empty($page))
{
$page=1;
}
mysql_free_result($q_ry);
$goto=($page-1)*$pagesize;
$sql_select_mem="Select * From useradmin order by id asc limit $goto,$pagesize";
$fect=mysql_query($sql_select_mem);
if(!$fect)
{
("ติดต่อฐานข้อมูลไม่ได้".mysql_error());
exit;
}
$bgcount=0;
while($rows=mysql_fetch_array($fect))
{
$idx =$rows['id'];
$userid =$rows['userid'];
$admin_name = $rows['name'];
$position = $rows['position'];
$de_partid = $rows['departid'];
$password = $rows['password'];
//$re_direct = $rows['redirect'];
$Status = $rows['Status]';
$bgcount=$bgcount+1;
$bgmod=$bgcount%2;
if($bgmod==0){
$bgcolor="#E1DFD7";
}else{
$bgcolor="#FDFBF4";
}
$a=number_format($salary,2,'.',',');
?>
<table width="100%" border="0" cellspacing="1" cellpadding="1">
<tr>
<td width="545" bgcolor=<? echo "$bgcolor"; ?>>
<div align="left"></div>
<div align="left"></div>
<div align="center"> </div>
<div align="left"><img src="images/arrow.jpg" width="5" height="12"><font color="#993300" size="2">
<? echo "[ $userid ] $admin_name<br>ตำแหน่ง : $position "; ?></font></div></td>
<td width="54"> <div align="center"><a href="EditUser.php?ID=<? echo "$idx"; ?>"><img src="images/pencil.jpg" width="20" height="20" border="0"></a>
<a href="DelUser.php?del_id=<? echo "$idx"; ?>"><img src="images/delete.png" width="22" height="22" border="0"></a>
</div></td>
</tr>
</table>
<?
}
}
?>
</td>
</tr>
<tr class="jobscss">
<td height="19"> </td>
</tr>
<tr class="jobscss">
<td><strong><span class="maekhawtom"><font color="#990000" size="2">หน้าที่
:</font></span></strong> <font color="#999999" size="2"><span class="maekhawtom">
<?
for($i=1;$i<$page;$i++)
{
echo"[<a href='$PHP_SELF?page=$i'><font size=2 color='#000000'>$i</font></a>]";
}
echo"[<font size=2 color=#000000><b><font size=2 color='#FF00000'>$page</font></b></font>]";
for($i=$page+1;$i<=$totalpage;$i++)
{
echo"[<a href='$PHP_SELF?page=$i'><font size=2 color='#000000'>$i</font></a>]";
}
?>
</span></font><font color="#FFFFFF" size="2"><span class="maekhawtom">
</span></font></td>
</tr>
<tr>
<td><div align="center"></div></td>
</tr>
</table>
</div></td>
<td><img src="spacer.gif" width="1" height="20" border="0" alt=""></td>
</tr>
<tr>
<td><img name="bxx_r3_c1" src="images/bxx_r3_c1.jpg" width="673" height="8" border="0" alt=""></td>
<td><img src="spacer.gif" width="1" height="8" border="0" alt=""></td>
</tr>
</table>
</div></td>
</tr>
</table>
</div></td>
</tr>
</table>
</div></td>
</tr>
<tr>
<td><img name="bx_r3_c1" src="images/bx_r3_c1.jpg" width="945" height="9" border="0" alt=""></td>
</tr>
</table>
<br>
</body>
</html>
Tag : PHP, MySQL
|
|
|
|
|
|
Date :
2012-08-08 17:47:56 |
By :
golfharo |
View :
1088 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุณคับ
ขอศึกษาแปป
ไม่เข้าใจเด๋วมาถามใหม่
|
|
|
|
|
Date :
2012-08-09 13:03:56 |
By :
golfharo |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|