สอบถามเรื่องการใช้ List กับ Database หน่อยครับ
ถาม-ตอบ แนะนำไอเดียว โค้ดตัวอย่าง แนวทาง วิธีแก้ปัญหา สอบถามเรื่องการใช้ List กับ Database หน่อยครับ
สอบถามเรื่องการใช้ List กับ Database หน่อยครับ
Copy
ต้องการสร้าง form การแก้ไขข้อมูลโดยดึงค่าจาก DB มาไว้ใน รูปแบบต่างๆ เช่น Textbox , Textarea, List , checkbox เป็นต้น ทั้งนี้ผมสามารถดึงข้อมูลมาแสดงผลได้ตามที่ศึกษาโค้ดของอาจารย์ ครับ แต่ติดประเด็นเรื่องของ List กับ Checkbox ไม่สามารถนำค่าที่มีอยู่แล้วมาแสดงได้ครับ ทั้งนี้ผมมี Database และ Code แนบมาด้วยเพื่อขอคำชี้แนะครับ ขอบคุณครับ
Database มี 2 Table ดังนี้
- t_Memberstatus --> ID, Following_Details ex. (1, รอชำระเงิน / 2, ติดต่อไม่ได้ / 3, ประสงค์ยกเลิก / 4, กำลังดำเนินการ)
- t_following --> Member_Code, Member_Type_Name, Member_Name, Address, Province, Tel, Fax, Email, Status, TotalYear, Period, Balances, MoreInfo, Following_ID
-----------------------------
Index.php
![]()
Database มี 2 Table ดังนี้
- t_Memberstatus --> ID, Following_Details ex. (1, รอชำระเงิน / 2, ติดต่อไม่ได้ / 3, ประสงค์ยกเลิก / 4, กำลังดำเนินการ)
- t_following --> Member_Code, Member_Type_Name, Member_Name, Address, Province, Tel, Fax, Email, Status, TotalYear, Period, Balances, MoreInfo, Following_ID
-----------------------------
Index.php
<html>
<head>
<title>GS1 Thailand Membership</title>
<!-- bootstrap -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<!-- Select2 -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.min.css" rel="stylesheet" />
</head>
<body>
<?php
ini_set('display_errors', 1);
error_reporting(~0);
$strKeyword = null;
if(isset($_POST["txtKeyword"]))
{
$strKeyword = $_POST["txtKeyword"];
}
if(isset($_GET["txtKeyword"]))
{
$strKeyword = $_GET["txtKeyword"];
}
?>
<form name="frmSearch" method="post" action="<?php echo $_SERVER['SCRIPT_NAME'];?>">
<div class="card">
<div class="card-header bg-secondary text-white">
<h5><i class="fa fa-user-circle-o " aria-hidden="true"></i>
<table width="599" align="center" style="font-size:20px">
<tr><h1 align="center">
ระบบตรวจสอบข้อมูลสมาชิกค้างชำระ<br>
</h1></tr>
<tr align="center">
<th>Keyword:
<input style="font-size:20px" name="txtKeyword" type="text" id="txtKeyword" value="<?php echo $strKeyword;?>">
<input style="font-size:20px" type="submit" value="Search"></th>
</tr>
<tr> <th style="color: #ff6600"><br>**สามารถค้นหาโดยใช้เลข GLN / ชื่อบริษัท / จังหวัด</th>
</tr>
</table>
</h5>
</div></div>
</form>
<?php
$serverName = "localhost";
$userName = "gs1th";
$userPassword = "wailum1983";
$dbName = "gs1income_th";
$conn = mysqli_connect($serverName,$userName,$userPassword,$dbName);
$sql = "SELECT t_memberstatus.Member_Code, t_memberstatus.Member_Name, t_memberstatus.Member_Type_Name, t_memberstatus.Province, t_memberstatus.Period, t_memberstatus.Balances, t_follwing.Follwing_Details, t_memberstatus.MoreInfo FROM t_memberstatus inner JOIN t_following on Following_ID = t_following.ID WHERE (Member_Code LIKE '%".$strKeyword."%' or Member_Name LIKE '%".$strKeyword."%' or Province LIKE '%".$strKeyword."%') ";
$query = mysqli_query($conn,$sql);
$num_rows = mysqli_num_rows($query);
$per_page = 30; // Per Page
$page = 1;
if(isset($_GET["Page"]))
{
$page = $_GET["Page"];
}
$prev_page = $page-1;
$next_page = $page+1;
$row_start = (($per_page*$page)-$per_page);
if($num_rows<=$per_page)
{
$num_pages =1;
}
else if(($num_rows % $per_page)==0)
{
$num_pages =($num_rows/$per_page) ;
}
else
{
$num_pages =($num_rows/$per_page)+1;
$num_pages = (int)$num_pages;
}
$row_end = $per_page * $page;
if($row_end > $num_rows)
{
$row_end = $num_rows;
}
$sql .= " ORDER BY Member_Code ASC LIMIT $row_start ,$row_end ";
$query = mysqli_query($conn,$sql);
?>
<table width="100%" border="1">
<tr style="font-size:20px">
<th> <div width="150" align="center">รหัสสมาชิก</div></th>
<th> <div width="200" align="center">ชื่อบริษัท</div></th>
<th> <div width="80" align="center">ประเภทสมาชิก</div></th>
<th> <div width="150" align="center">จังหวัด</div></th>
<th> <div width="120" align="center">ปีที่ค้าง</div></th>
<th> <div width="80" align="center">จำนวนเงิน</div></th>
<th> <div width="80" align="center">สถานะการติดตาม</div></th>
<th> <div width="500" align="center">หมายเหตุ</div></th>
</tr>
<?php
while($result=mysqli_fetch_array($query,MYSQLI_ASSOC))
{
?>
<tr style="font-size:16px">
<td><div align="center"><?php echo $result["Member_Code"];?></div></td>
<td><?php echo $result["Member_Name"];?></td>
<td align="center"><?php echo $result["Member_Type_Name"];?></td>
<td align="center"><?php echo $result["Province"];?></td>
<td align="center"><?php echo $result["Period"];?></td>
<td align="center"><?php echo number_format($result["Balances"]);?></td>
<td align="center"><?php echo $result["Following_Details"];?></td>
<td align="center" width="500"><?php echo $result["MoreInfo"];?></td>
<td align="center"><a href='UserUpdateForm.php?Member_Code=<?php echo $result["Member_Code"]; ?>'>edit</a></td>
</tr>
<?php
}
?>
</table>
<br>
Total <?php echo $num_rows;?> Record : <?php echo $num_pages;?> Page :
<?php
if($prev_page)
{
echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$prev_page&txtKeyword=$strKeyword'><< Back</a> ";
}
for($i=1; $i<=$num_pages; $i++){
if($i != $page)
{
echo "[ <a href='$_SERVER[SCRIPT_NAME]?Page=$i&txtKeyword=$strKeyword'>$i</a> ]";
}
else
{
echo "<b> $i </b>";
}
}
if($page!=$num_pages)
{
echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$next_page&txtKeyword=$strKeyword'>Next>></a> ";
}
$conn = null;
?>
</body>
</html>
-----------------------------------คำแนะนำ และการใช้งาน
สมาชิก กรุณา ล็อกอินเข้าระบบ เพื่อตั้งคำถามใหม่ หรือ ตอบคำถาม สมาชิกใหม่ สมัครสมาชิกได้ที่ สมัครสมาชิก
- ถาม-ตอบ กรุณา ล็อกอินเข้าระบบ
เว็บไซต์ของเราให้บริการเนื้อหาบทความสำหรับนักพัฒนา โดยพึ่งพารายได้เล็กน้อยจากการแสดงโฆษณา
โปรดสนับสนุนเว็บไซต์ของเราด้วยการปิดการใช้งานตัวปิดกั้นโฆษณา (Disable Ads Blocker) ขอบคุณครับ