|
 |
|
แก้ไขข้อมูลไม่ได้รบกวนดูโค้ดให้หน่อยได้ไหมค่ะ. ..ขอบคุณมา ณ. ที่นี้นะค่ะ ต้องส่งงานพรุ่งนี้ค่ะ |
|
 |
|
|
 |
 |
|
Code (PHP)
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?
include ("connet.php");
?>
<?
$page=$_GET[page];
if ($page==""){
$page=1;
}
$each=10;
$sql_news = "SELECT * FROM news;";
$result_news = mysql_query($sql_news);
$totals=mysql_num_rows($result_news);
$totalpages=ceil($totals/$each);
$goto=($page-1)*$each;
$sql_news="SELECT * FROM news ORDER BY news_id DESC limit $goto,$each;";
$result_news=mysql_query($sql_news);
?>
<?
//การสร้าง Autorun รหัสประเภทสินค้า นั่นเอง
$sql="select max(news_id) as news_id from news";
$result=mysql_query($sql) or die(mysql_error());//การ error Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in ส่วนใหญ่เป็นเพราะตรงนี้
$dbarr=mysql_fetch_array($result);
if($dbarr){
$total= $dbarr['news_id']+1;
if (strLen($total)=="1"){
$total="0".$total;
}else{
$total= $total;
}
}else{
$total= $id_news;
}
?>
<form method="post" action="news_action.php?do=add">
<table width="587" border="0" align="center">
<tr align="right" valign="bottom">
<th scope="col">::<strong><img src="20121116050143551_easyicon_cn_32.png" alt="" width="20" height="20" /></strong> เพิ่มข่าวสารประชาสัมพันธ์::</th>
</tr>
</table>
<table width="587" border="0" align="center">
<tr align="right" >
<td width="143">รหัสข่าวสาร ::</td>
<td width="434" align="left" ><?=$total; ?>
</td>
</tr>
<tr >
<td align="right">หัวข้อข่าวสาร ::</td>
<td><label for="news_title"></label>
<input name="news_title" type="text" id="news_title" size="50" /></td>
</tr>
<tr >
<td align="right">รายละเอียดข่าวสาร ::</td>
<td><label for="news_detail"></label>
<textarea name="news_detail" cols="50" rows="6" id="news_detail"></textarea></td>
</tr>
<tr >
<td align="right">วันที่ประกาศ ::</td>
<td><label for="news_date"></label>
<input name="news_date" type="text" id="news_date" value="<?php echo date('Y-m-d');?>" /></td>
</tr>
<tr align="right">
<td colspan="2"><div align="center">
<input type="submit" name="button" id="button" value="เพิ่มข่าวสาร" />
<input type="reset" name="button2" id="button2" value="ยกเลิก" />
<input type="hidden" name="id_news" value="<?=$total; ?>" />
</div></td>
</tr>
</table>
</form>
<table width="601" border="0" align="center">
<tr>
<th colspan="6" align="center" scope="col">จัดการข้อมูลข่าวประกาศ ประชาสัมพันธ์ </th>
</tr>
<tr align="center">
<td width="80">ลำดับที่</td>
<td width="126">หัวข้อข่าวสาร</td>
<td width="154">วันที่ประกาศ</td>
<td width="98">รายละเอียด</td>
<td width="57">แก้ไข</td>
<td width="60">ลบ</td>
</tr>
<?
while ($dbarr_news = mysql_fetch_array($result_news)){
?>
<tr align="center">
<td><? echo $dbarr_news['news_id'] ?></td>
<td><? echo $dbarr_news['news_title'] ?></td>
<td><? echo $dbarr_news['news_date'] ?></td>
<td align="center"><a href="shownews1.php?ty=<?=$dbarr_news['news_id'] ?>"><img src="20121116050309842_easyicon_cn_128.png" width="20" height="20" /></a></td>
<td><a href ="news_action.php?do=frmedit&id=<? echo $dbarr_news['news_id']; ?>"><img src="20121116050301729_easyicon_cn_80.png" alt="" width="20" height="20" /></a></td>
<td align="center"><a href="news_action.php?do=delete&id=<? echo $dbarr_news['news_id'] ?>"><img src="20121116050436121_easyicon_cn_128.png" alt="" width="20" height="20" /></a></td>
</tr>
<?
}
?>
<tr>
<td colspan="4">รวมทั้งหมด <?=$totals?> รายการ :
<? //Code ใช้ เมื่อ จำนวนหน้ามากกว่า 1 หน้า
if($totalpages>1) {
for ($i=1;$i<=$totalpages;$i++){
if($i==$page) {
echo "<b>หน้า $page </b>";
} else {
echo " | <a href=\"news.php?page=$i\">$i</a> ";
}
}
}
?></td>
</table>
Code (PHP)
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?
include "connet.php";
if ($_POST['do']=="add"){
$id_news=$_POST['news_id'];
$title=$_POST['news_title'];
$detile=$_POST['news_detail'];
$news_date=$_POST['news_date'];
$sql="select * from news where news_title='$news_title'";
$result=mysql_query($sql) or die(mysql_error());// error Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource แก้ตรงนี้
$num=mysql_num_rows($result);
if($num>0){
echo"<h1>ชื่อหัวข้อข่าวสารซ้ำ</h1>";
echo"<meta http-equiv='refresh' content='2;url=news.php'>";
}else{
$sql_add = "INSERT INTO news (news_id ,news_title,news_detail,news_date) VALUES ('$news_id','$news_title','$news_detail','$news_date');";
$result_add=mysql_query($sql_add);
echo "<script language='javascript'>";
echo "alert('เพิ่มข้อมูลข่าวสารเรียบร้อยแล้ว');";
echo "window.location='news.php';";
echo "</script>";
}
}elseif ($_GET['do']=="delete"){
$sql="DELETE FROM news WHERE news_id='$_REQUEST[id]';";
$result=mysql_query($sql);
if($result){
echo "<script language='javascript'>";
echo "alert('ลบข้อมูลข่าวสารเรียบร้อยแล้ว');";
echo "window.location='news.php';";
echo "</script>";
}
elseif ($_GET['do']=="frmedit"){//ต้องมีการโหลด From ขึ้นมาใหม่...ถ้า ['do']=="frmedit" จริง มันจะใช้คำสั่ง$sql="SELECT * FROM tbcategory WHERE catid =$_POST[id]"; คือเรียกขึ้นม่า 1 record
$sql="SELECT * FROM news WHERE news_id =$_GET[id]";//เมื่อคลิก ปุ่มแก้ไขมันจะส่งค่าไป
$result=mysql_query($sql);
$dbarr=mysql_fetch_array($result);
?>
<form method="post" action="news_action.php?do=edit">
<table width="667" border="0" align="center">
<tr align="right" valign="middle">
<td scope="col">::แก้ไขข้อมูลข่าวสารประชาสัมพันธ์::</td>
</tr>
</table>
<table width="667" border="0" align="center">
<tr align="right" >
<td width="151">รหัสข่าวสาร::</td>
<td align="left"><?=$dbarr['news_id']; ?></td>
</tr>
<tr >
<td align="right">หัวข้อข่าวสาร ::</td>
<td><label for="titlee"></label>
<input name="news_title" type="text" id="news_title" value="<?=$dbarr['news_title']; ?>"/></td>
</tr>
<tr >
<td align="right">รายละเอียดข่าวสาร ::</td>
<td><label for="news_detail"></label>
<textarea name="news_detail" cols="50" rows="5" id="news_detail"><?=$dbarr['news_detail']; ?>
</textarea></td>
</tr>
<tr >
<td align="right">วันที่ประกาศ ::</td>
<td><label for="news_date"></label>
<input name="news_date" type="text" id="news_date" value="<?=$dbarr['news_date']; ?>" /></td>
</tr>
<tr align="right">
<td colspan="2">
<div align="center">
<input type="hidden" name="id" value="<?=$dbarr['news_id'];?>">
<input type="submit" name="button" id="button" value="บันทึก" />
<input type="reset" name="button2" id="button2" value="ยกเลิก" />
</div></td>
</tr>
</table>
</form>
<?
}elseif ($_GET['do']=="edit"){
$news_id=$_POST['id'];
$news_title=$_POST['news_title'];
$news_detail=$_POST['news_detail'];
$news_date=$_POST['news_date'];
$sql_update = "UPDATE news SET news_title='".$news_title."',news_detail='".$news_detail."' WHERE news_id'".$_POST["id"]."'";
$reslut_update=mysql_query($sql_update) or die(mysql_error());
if($result_update){
echo "<script language='javascript'>";
echo "alert('แก้ไขข้อมูลข่าวสารเรียบร้อยแล้ว');";
echo "window.location='news.php';";
echo "</script>";
echo "<meta http-equiv='refresh' content='2;url=news.php'>";
}else{
echo "<script language='javascript'>";
echo "alert('ไม่สามารถแก้ไขข้อมูลข่าวสารได้');";
echo "window.location='news.php';";
echo "</script>";
}
}
}
?>
Tag : PHP, MySQL, HTML/CSS, JavaScript, jQuery, CakePHP

|
|
 |
 |
 |
 |
Date :
2012-12-16 00:39:59 |
By :
อัลต้า |
View :
874 |
Reply :
3 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
|
|

|
Load balance : Server 01
|