|
 |
|
ขอคำแนะนำ การกดปุ่มแล้วให้แสดงเป็น Popup ขึ้นแทน ไม่ให้แสดงไปอีกหน้า |
|
 |
|
|
 |
 |
|
กำลังทำเกี่ยวกับการแก้ไข ข้อมูลในตารางค่ะ แต่ที่ทำได้ตินนี้คือพอกดปุ่มแก้ไข มันจะไปแสดงฟอร์มอีกหน้าหนึ่งแทน ซึ่งอยากให้ตัวฟอร์มที่เด้งไปอีกหน้าหนึ่งเป็นตัว Popup ขึ้นมาแทน ไม่ให้ไปแสดงอีกหน้าหนึ่ง จะได้ไหมคะ ไม่รู้ต้องทำยังไง รบกวนด้วยจ้าาา
Code (PHP) create.php
<?php
$host = "localhost";
$user = "root";
$pass = "";
$dbname = "db_project";
mysql_connect($host, $user, $pass);
mysql_select_db($dbname);
mysql_query("SET NAMES UTF8");
$sql = "SELECT * FROM tb_crefunds ORDER BY id ASC";
$rs = mysql_query($sql);
?>
<table width="600" border="1">
<tr>
<th>ลำดับ</th>
<th>ปีดำเนินงาน</th>
<th>รหัสกองทุน</th>
<th>ชื่อกองทุน</th>
<th>คำสั่ง</th>
</tr>
<?php
while($row = mysql_fetch_array($rs)) {
echo "<tr>" .
"<td align='center'>" . $row['id'] . "</td>" .
"<td>" . $row['wYear'] . "</td>" .
"<td align='right'>" . $row['codeFund'] . "</td>" .
"<td align='center'>" . $row['nmFund'] . "</td>" .
"<td align='center'>" .
"<a href='editpro.php?id=" . $row['id'] . "'>แก้ไข</a> " .
"<a href='delprocess.php?id=" . $row['id'] . "'>ลบ</a>" .
"</td>".
"</tr>";
}
?>
</table>
อีก Code คือ ตัวที่แสดงฟอร์มแก้ไขอีกหน้า
Code (PHP) edit.php
<?php
// ก่อนอื่นทำการรับ id ที่ส่งมาทาง query string ก่อนเลยครับ
$id = $_GET['id'];
// จากนั้นทำการเชื่อมฐานข้อมูล
mysql_connect("localhost", "root", "");
mysql_select_db("db_project");
mysql_query("SET NAMES UTF8");
// เมื่อเราเชื่อมฐานข้อมูลเรียบร้อยแล้วให้เราทำการคิวรี่หา detail ของ id ที่เรารับค่ามา
$sqlDetail = "SELECT * FROM tb_crefunds WHERE id = '$id'";
$rs = mysql_query($sqlDetail);
// เนื่องจากว่าข้อมูลที่ได้กลับมานั้นมีเพียงเรคอร์ดเดียวเท่านั้น (เพราะว่า id นั้น ๆ จะเป็นคุณสมบัติ unique)
// ซึ่ง id หนึ่งมีได้เพียงข้อมูลแถวเดียวเท่านั้น ดังนั้นเราก็ไม่จำเป็นต้องทำการวนลูปเพื่อดึงข้อมูลจาก resource
$row = mysql_fetch_array($rs);
$wYear = $row['wYear'];
$codeFund = $row['codeFund'];
$nmFund = $row['nmFund'];
/* หรือจะใช้เป็นคำสั่งนี้ก็ได้ครับ
list($prod_name, $price, $quantity) = $row;
*/
?>
<!-- มาถึงส่วนของสร้างหน้าฟอร์มแก้ไขข้อมูลแล้วครับ -->
<html>
<head>
<title>แก้ไขข้อมูล</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<form method="post" action="editprocess.php">
<input type="hidden" name="id" value="<?=$id?>" />
<table width="500" border="1">
<tr>
<td>ปีดำเนินงาน:</td>
<td><input type="text" name="wYear" value="<?=$wYear?>" /></td>
</tr>
<tr>
<td>รหัสกองทุน:</td>
<td><input type="text" name="codeFund" size="5" value="<?=$codeFund?>" /></td>
</tr>
<tr>
<td>ชื่อกองทุน:</td>
<td><input type="text" name="nmFund" size="5" value="<?=$nmFund?>" /></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="บันทึก" /></td>
</tr>
</table>
</form>
</body>
ซึ่งอยากให้ตรงไฟล์ edit.php กลายเป็น Popup แทน ให้อยู่ในหน้า create.php เลยได้ไหมคะ
รบกวนด้วยจ้าา ขอบคุณล่วงหน้านะคะ :)
Tag : PHP, HTML/CSS, JavaScript, Ajax, jQuery, CakePHP

|
|
 |
 |
 |
 |
Date :
2012-01-28 02:14:27 |
By :
porn_toon |
View :
3648 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณคะะ
เล่น jQuery ค่ะ เด๋วลองเอาไปใช้ดูนะคะ 
|
 |
 |
 |
 |
Date :
2012-01-28 19:02:33 |
By :
porn_toon |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 05
|