สอบถามเรื่องการใช้ List กับ Database หน่อยครับ
ถาม-ตอบ แนะนำไอเดียว โค้ดตัวอย่าง แนวทาง วิธีแก้ปัญหา สอบถามเรื่องการใช้ List กับ Database หน่อยครับ
สอบถามเรื่องการใช้ List กับ Database หน่อยครับ
ต้องการสร้าง 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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | <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 --> <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> |
1 |

คำแนะนำ และการใช้งาน
สมาชิก กรุณา ล็อกอินเข้าระบบ เพื่อตั้งคำถามใหม่ หรือ ตอบคำถาม สมาชิกใหม่ สมัครสมาชิกได้ที่ สมัครสมาชิก
- ถาม-ตอบ กรุณา ล็อกอินเข้าระบบ
ความคิดเห็นที่
1
UserUpdateForm.php
![]()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | <meta charset= "UTF-8" > <?php //1. เชื่อมต่อ database: include ( 'db_connection.php' ); //ไฟล์เชื่อมต่อกับ database ที่เราได้สร้างไว้ก่อนหน้าน้ี //ตรวจสอบถ้าว่างให้เด้งไปหน้าหลัก if ( $_GET [ "Member_Code" ] == ' ' ){ echo "<script type='text/javascript'>" ; echo "alert('Error Contact Admin !!');" ; echo "window.location = 'index.php'; " ; echo "</script>" ; } //รับค่าไอดีที่จะแก้ไข /** @var type $_GET */ /** @var type $Member_Code */ $Member_Code = mysqli_real_escape_string( $con , $_GET [ 'Member_Code' ]); //2. query ข้อมูลจากตาราง: $sql = "SELECT * FROM t_memberstatus WHERE Member_Code='$Member_Code' " ; $result = mysqli_query( $con , $sql ) or die ( "Error in query: $sql " . mysqli_error()); $row = mysqli_fetch_array( $result ); extract( $row ); ?> <form action= "userupdate_db.php" method= "post" name= "updateuser" id= "updateuser" > <table width= "700" border= "0" align= "center" cellpadding= "0" cellspacing= "0" > <tr> <td height= "40" colspan= "2" align= "center" bgcolor= "#D6D5D6" ><b>บันทึกข้อมูลการชำระเงิน</b></td> </tr> <tr> <td align= "right" bgcolor= "#EBEBEB" >Member_Code : </td> <td bgcolor= "#EBEBEB" > <p><input type= "text" name= "Member_Code" value= "<?php echo $Member_Code; ?>" disabled= 'disabled' /> <input type= "hidden" name= "Member_Code" value= "<?php echo $Member_Code; ?>" /> </td> </tr> <tr> <td align= "right" bgcolor= "#EBEBEB" > </td> <td bgcolor= "#EBEBEB" > </td> </tr> <tr> <td width= "200" align= "right" bgcolor= "#EBEBEB" >ชื่อบริษัท :</td> <td width= "583" bgcolor= "#EBEBEB" ><input name= "Member_Name" type= "text" id= "Member_Name" value= "<?=$Member_Name;?>" disabled= 'disabled' /></td> </tr> <tr> <td align= "right" bgcolor= "#EBEBEB" > </td> <td bgcolor= "#EBEBEB" > </td> </tr> <tr> <td width= "117" align= "right" bgcolor= "#EBEBEB" >ประเภทสมาชิก :</td> <td width= "583" bgcolor= "#EBEBEB" ><input name= "Member_Type_Name" type= "text" id= "Member_Type_Name" value= "<?=$Member_Type_Name;?>" disabled= 'disabled' /></td> </tr> <tr> <td align= "right" bgcolor= "#EBEBEB" > </td> <td bgcolor= "#EBEBEB" > </td> </tr> <tr> <td align= "right" bgcolor= "#EBEBEB" >ที่อยู่ :</td> <td bgcolor= "#EBEBEB" ><textarea name= "Address" type= "text" id= "Address" cols= "50" rows= "3" ><?= $Address ;?></textarea></td> </tr> <tr> <td align= "right" bgcolor= "#EBEBEB" > </td> <td bgcolor= "#EBEBEB" > </td> </tr> <tr> <td align= "right" bgcolor= "#EBEBEB" >จังหวัด :</td> <td bgcolor= "#EBEBEB" ><input name= "Province" type= "text" id= "Province" value= "<?=$Province;?>" size= "30" /></td> </tr> <tr> <td align= "right" bgcolor= "#EBEBEB" > </td> <td bgcolor= "#EBEBEB" > </td> </tr> <tr> <td align= "right" bgcolor= "#EBEBEB" >เบอร์โทรศัพท์ :</td> <td bgcolor= "#EBEBEB" ><input name= "Tel" type= "text" id= "Tel" value= "<?=$Tel;?>" size= "30" /></td> </tr> <tr> <td align= "right" bgcolor= "#EBEBEB" > </td> <td bgcolor= "#EBEBEB" > </td> </tr> <tr> <td align= "right" bgcolor= "#EBEBEB" >Email :</td> <td bgcolor= "#EBEBEB" ><input name= "Email" type= "text" id= "Email" value= "<?=$Email;?>" size= "50" /></td> </tr> <tr> <td align= "right" bgcolor= "#EBEBEB" > </td> <td bgcolor= "#EBEBEB" > </td> </tr> <tr> <td align= "right" bgcolor= "#EBEBEB" >Status :</td> <td bgcolor= "#EBEBEB" ><input name= "Status" type= "text" id= "Status" value= "<?=$Status;?>" disabled= 'disabled' /></td> </tr> <tr> <td align= "right" bgcolor= "#EBEBEB" > </td> <td bgcolor= "#EBEBEB" > </td> </tr> <tr> <td align= "right" bgcolor= "#EBEBEB" >จำนวนปีที่ค้างชำระ :</td> <td bgcolor= "#EBEBEB" ><input name= "TotalsYear" type= "text" id= "TotalsYear" value= "<?=$TotalsYear;?>" disabled= 'disabled' /></td> </tr> <tr> <td align= "right" bgcolor= "#EBEBEB" > </td> <td bgcolor= "#EBEBEB" > </td> </tr> <tr> <td align= "right" bgcolor= "#EBEBEB" >ปีที่ค้างชำระ :</td> <td bgcolor= "#EBEBEB" ><input name= "Period" type= "text" id= "Period" value= "<?=$Period;?>" disabled= 'disabled' /></td> </tr> <tr> <td align= "right" bgcolor= "#EBEBEB" > </td> <td bgcolor= "#EBEBEB" > </td> </tr> <tr> <td align= "right" bgcolor= "#EBEBEB" >จำนวนเงินค้างชำระ :</td> <td bgcolor= "#EBEBEB" ><input name= "Balances" type= "text" id= "Balances" value= "<?=number_format($Balances);?>" disabled= 'disabled' /></td> </tr> <tr> <td align= "right" bgcolor= "#EBEBEB" > </td> <td bgcolor= "#EBEBEB" > </td> </tr> <tr> <td align= "right" bgcolor= "#EBEBEB" >การติดตามหนี้ :</td> <td> <select name= "Follwing2" > <option value= "" ><-- Please Select Item --></option> <?php //คำสั่ง SQL และคำสั่งให้ทำงาน $sql1 = "select * from t_follwing ORDER BY ID ASC" ; $dbquery =mysqli_query( $sql1 ); while ( $objResuut = mysqli_fetch_array( $dbquery )) { if ( $strDefault == $objResuut [ "Following_ID" ] ) { $sel = "selected" ; } else { $sel = " " ; } ?> <option value = "<?php $objResuut[" Following_ID "];?>" ><?php $objResuut [ "Follwing_Details" ];?> </option> <?php } ?> </select> </td> </tr> <tr> <td align= "right" bgcolor= "#EBEBEB" >หมายเหตุ :</td> <td bgcolor= "#EBEBEB" ><br><textarea name= "MoreInfo" type= "text" id= "MoreInfo" " cols=" 50 " rows=" 3"><?= $MoreInfo ;?></textarea></td> </tr> <tr> <td align= "right" bgcolor= "#EBEBEB" > </td> <td bgcolor= "#EBEBEB" > </td> </tr> <tr> <td bgcolor= "#EBEBEB" > </td> <td bgcolor= "#EBEBEB" > </td> </tr> <tr> <td bgcolor= "#EBEBEB" > </td> <td bgcolor= "#EBEBEB" > <input type= "button" value= " ยกเลิก " onclick= "window.location='index.php' " /> <!-- ถ้าไม่แก้ไขให้กลับไปหน้าแสดงรายการ --> <input type= "submit" name= "Update" id= "Update" value= "Update" /></td> </tr> <tr> <td bgcolor= "#EBEBEB" > </td> <td bgcolor= "#EBEBEB" > </td> </tr> </table> </form> |

ความคิดเห็นที่
2
ในขั้นตอนการแก้ไข ที่เป็น List หรือ Select tag ถ้าจะให้ค่าไหนถูกเลือก จะต้องมี selected attribute กำกับ
option ค่านั้น เช่น
1 | <option value= "A" selected >A</option> |
ดั้งตัวแปร $sel ที่เก็บคำว่า "selected" ต้องถูกแทรกเข้าไปใน option
1 | <option value = "<?php $objResuut[" Following_ID "];?>" <?= $sel ?> ><?php $objResuut [ "Follwing_Details" ];?> </option> |
และต้องมั้นใจว่า เงื่อนไขการตรวจสอบกรณีค่าเป็น selected ถูกต้อง
1 2 3 4 5 6 7 8 | if ( $strDefault == $objResuut [ "Following_ID" ] ) { $sel = "selected" ; } else { $sel = " " ; } |
คือ $strDefault ต้องเป็นค่าจากข้อมูลเดิมที่เราแก้ไข แนวทางประมาณนั้น
>>> อัพเดท >>> 13-03-2020
------------------------------------------
ถ้าเป็น radio และ checkbox จะใช้เป็น "checked"
บทความแนะนำที่เกี่ยวข้อง | |
---|---|
การเพิ่ม ลบ แก้ไข แบ่งหน้า ข้อมูล ด้วย jquery ajax อย่างง่าย | อ่าน 39,018 |
แนวทาง การค้นหาจาก หลายรูปแบบ และแบ่งหน้า อย่างง่าย | อ่าน 16,590 |
ทบทวน เพิ่ม ลบ แก้ไข เช็คฟอร์ม แบ่งหน้า อัพรูป ในโค้ดเดียว | อ่าน 35,840 |
แจกโค้ด ajax เพิ่ม ลบ แก้ไข แบ่งหน้า ร่วมกัน bootstrap modal | อ่าน 37,904 |

ความคิดเห็นที่
3
เรียน อาจารย์ครับ
ใน DB ผมมีอยู่ Database มี 2 Table ดังนี้
- t_following --> ID, Following_Details ex. (1, รอชำระเงิน / 2, ติดต่อไม่ได้ / 3, ประสงค์ยกเลิก / 4, กำลังดำเนินการ)
ผมจะดึงข้อมูลที่อยู่ในนี้มาใส่ไว้ใน List เพื่อให้เลือกแล้วไปเก็บไว้ใน t_Memberstatus ลอง query ตรงๆแล้วมันก็ยังไม่ขึ้นอ่ะครับ
- t_Memberstatus--> Member_Code, Member_Type_Name, Member_Name, Address, Province, Tel, Fax, Email, Status, TotalYear, Period, Balances, MoreInfo, Following_ID
ยังหาจุดที่แก้ไม่เจอครับ
ใน DB ผมมีอยู่ Database มี 2 Table ดังนี้
- t_following --> ID, Following_Details ex. (1, รอชำระเงิน / 2, ติดต่อไม่ได้ / 3, ประสงค์ยกเลิก / 4, กำลังดำเนินการ)
ผมจะดึงข้อมูลที่อยู่ในนี้มาใส่ไว้ใน List เพื่อให้เลือกแล้วไปเก็บไว้ใน t_Memberstatus ลอง query ตรงๆแล้วมันก็ยังไม่ขึ้นอ่ะครับ
- t_Memberstatus--> Member_Code, Member_Type_Name, Member_Name, Address, Province, Tel, Fax, Email, Status, TotalYear, Period, Balances, MoreInfo, Following_ID
ยังหาจุดที่แก้ไม่เจอครับ
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | <select name= "Following_ID" > <option value= "" ><-- Please Select Item --></option> <?php $sql1 = "select * from t_following ORDER BY ID ASC" ; $dbquery =mysqli_query( $sql1 ); while ( $objResuut = mysqli_fetch_array( $dbquery )) { if ( $strDefault == $objResuut [ "Following_ID" ] ) { $sel = "selected" ; } else { $sel = " " ; } ?> <option value = "<?php $objResuut[" Following_ID "];?>" selected><?php $objResuut [ "Following_Details" ];?> </option> |
1 2 3 4 5 6 7 8 9 | <?php } ?> </select> ลองใช้อีกวิธี คือฝั่งค่าไปเลย และเรียกข้อมูลที่อยู่ใน t_<span style= "color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 14px; background-color: rgb(248, 248, 248);" >Memberstatus ใน field </span>Following_ID ที่ join กับ t_<span style= "color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 14px; background-color: rgb(248, 248, 248);" >following</span><span style= "color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 14px; background-color: rgb(248, 248, 248);" > แล้วมันขึ้นข้อมูลที่ได้มีการเลือกไว้ แต่พอ Update ข้อมูลเดิม มันส่งค่า 0 ไปทำให้ข้อมูลมีการเปลี่ยนแปลง ถ้าใช้วิธีนี้จะทำยังไงให้ส่งค่าเดิมกลับไปครับ </span> |
<td bgcolor="#EBEBEB"><input name="Following_ID" type="text" id="Following_Details" value="<?=$Following_Details;?>" disabled='disabled'/>
<?php echo $Following_ID ;?>
<select name="Following_ID">
<option disabled="true" value="<?=$Following_ID;?>" selected><?=$Following_Details;?></option>
<option value="1">รอชำระเงิน</option>
<option value="2">ติดต่อไม่ได้</option>
<option value="3">ประสงค์ยกเลิก</option>
<option value="0">กำลังดำเนินการ</option>
</select>
</td>
![]()
ที่วงไว้คือค่าเดิมที่มีใน DB ครับ ถ้ากด update โดยไม่มีการเปลี่ยนแปลงข้อมูล มันจะส่งค่า 0 ไป เก็บอัตโนมัติ แต่ถ้ามีการเปลี่ยนแปลงก็จะส่งค่านั้นๆ ไป
อยากให้มันส่งค่าเดิมกลับไปถ้าไม่มีการเปลี่ยนแปลง ถ้ามีการกด update ครับ
รบกวนอาจารย์ด้วยครับ (ผมมือใหม่มากๆๆๆ)
ที่วงไว้คือค่าเดิมที่มีใน DB ครับ ถ้ากด update โดยไม่มีการเปลี่ยนแปลงข้อมูล มันจะส่งค่า 0 ไป เก็บอัตโนมัติ แต่ถ้ามีการเปลี่ยนแปลงก็จะส่งค่านั้นๆ ไป
อยากให้มันส่งค่าเดิมกลับไปถ้าไม่มีการเปลี่ยนแปลง ถ้ามีการกด update ครับ
รบกวนอาจารย์ด้วยครับ (ผมมือใหม่มากๆๆๆ)

ความคิดเห็นที่
4
element ไหนที่จะส่งค่าไปใช้ ต้องไม่กำหนด disabled
อย่าง input name="Following_ID" ด้านบน เรากำหนด disabled ค่าจากตัวแปรนี้จะไม่่ถูกส่งไป
1 2 3 4 5 6 7 8 9 | <input name= "Following_ID" type= "text" id= "Following_Details" value= "<?=$Following_Details;?>" disabled= 'disabled' /> <?php echo $Following_ID ;?> <select name= "Following_ID" > <option value= "" >เลือกสถานะการติดตาม</option> <option value= "1" <?=( $Following_ID == 1)? " selected" : "" ?> >รอชำระเงิน</option> <option value= "2" <?=( $Following_ID == 2)? " selected" : "" ?>>ติดต่อไม่ได้</option> <option value= "3" <?=( $Following_ID == 3)? " selected" : "" ?>>ประสงค์ยกเลิก</option> <option value= "0" <?=( $Following_ID == 0)? " selected" : "" ?>>กำลังดำเนินการ</option> </select> |
ตอนแก้ไข ให้ขึ้นรายการเริ่มต้นที่ถูกเลือก หรือค่าเดิมจาก DB ถ้าไม่มีการเปลี่ยนแปลง ค่านั้นๆ ก็จะถูกส่งกลับไปใช้งาน
แต่ถ้ามีการเปลี่ยน ค่าก็จะเปลียนไปตามค่าใหม่ที่เลือก กรณีเริ่มต้น ต้องฝึกเยอะๆ

ความคิดเห็นที่
5
ทำได้แล้วครับ ขอบพระคุณมากครับ










ขอบคุณทุกการสนับสนุน
![]()