|
 |
|
รบกวนช่วยหน่อยค่ะ รื่องการลบข้อมูลและแก้ไข คือว่าต้องการให้เรื่องข้อมูลจากเช็คบ๊อกแล้วให้กดปุ่มลบ |
|
 |
|
|
 |
 |
|
คือว่าต้องการให้เรื่องข้อมูลจากเช็คบ๊อกแล้วให้กดปุ่มลบ แล้วให้ลบข้อมูลออกจากฐานข้อมูลค่ะแล้วก็ให้คลิกหัวข้อแล้วให้ลิงค์ไปหน้าแก้ไขค่ะ ตอนนี้สามารถแก้ไขได้แล้วค่ะ แต่พอเวลาให้มันค่าข้อมูลที่หน้าข้อมูลมันไม่ยอมส่งมาค่ะมันไม่ยอมขึ้นในเท็กบ๊อกให้อ่ะค่ะ
นี้คือโค๊ดหน้าข้อมูลค่ะ
<form action ="deltest.php" method="post">
<?
$link=mysql_connect("localhost","root","14291530");
mysql_query("Use Examination;");
mysql_query("SET NAMES tis620");
mysql_query("SET collection_connection='tis620_thai_ci'");
$objDB = mysql_select_db("Examination");
$strSQL = "SELECT * FROM examdata ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$Num_Rows = mysql_num_rows($objQuery);
$Per_Page = 5; // Per Page
$Page = $_GET["Page"];
if(!$_GET["Page"])
{
$Page=1;
}
$Prev_Page = $Page-1;
$Next_Page = $Page+1;
$Page_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;
}
$strSQL .=" order by no ASC LIMIT $Page_Start , $Per_Page";
$objQuery = mysql_query($strSQL);
?>
<table align="center" width="910">
<tr bgcolor="#FF9900">
<td width="65" align="center"><b>เลือก </b> </td>
<td width="50" align="center"><b>ข้อที่ </b></td>
<td width="159" align="center"><b>คำถาม</b></td>
<td width="120" align="center"><b>choice1</b></td>
<td width="120" align="center"><b>choice2</b></td>
<td width="120" align="center"><b>choice3</b></td>
<td width="120" align="center"><b>choice4</b></td>
<td width="120" align="center"><b>คำตอบ</b></td>
</tr>
<?
while($objResult = mysql_fetch_array($objQuery,MYSQL_ASSOC))
{
?>
<tr bgcolor="#ffffff">
<td align=center><input type=checkbox name="checkbox[]" value=<?=$objResult["no"];?></td>
<td><font face="Ms Sans serif"><center><?=$objResult["no"];?></center></font></td>
<td><font face="Ms Sans serif"> <a href="edittest_from.php?id=<?=$objResult["no"];?>" target="<?=$objResult["no"];?>"><?=$objResult["question"]; ?><? $edit=$_POST["no"] ?></a></font></td>
<td><font face="Ms Sans serif"><?=$objResult["choice1"];?></font></td>
<td> <font face= "Ms Sans serif"><?=$objResult["choice2"];?></font> </td>
<td> <font face= "Ms Sans serif"><?=$objResult["choice3"];?></font> </td>
<td> <font face= "Ms Sans serif"><?=$objResult["choice4"];?></font> </td>
<td> <font face= "Ms Sans serif"><?=$objResult["answer"];?></font> </td>
</tr>
<?
}
?>
<tr>
<td colspan="3" align="center"><input type="submit" name="delete" value="ลบข้อสอบ">
</td> </form>
<form action="inserttest_from.php" method="post">
<td><input type="submit" name="insert" value="เพิ่มข้อสอบ"></td>
</form>
</tr>
</table>
<br>
Total <?= $Num_Rows;?> Record : <?=$Num_Pages;?> Page :
<?
if($Prev_Page)
{
echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page'><< Back</a> ";
}
for($i=1; $i<=$Num_Pages; $i++){
if($i != $Page)
{
echo "[ <a href='$_SERVER[SCRIPT_NAME]?Page=$i'>$i</a> ]";
}
else
{
echo "<b> $i </b>";
}
}
if($Page!=$Num_Pages)
{
echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page'>Next>></a> ";
}
mysql_close($link);
?>
</form>
อันนี้คือโค๊ดหน้าลบค่ะ
<?
$link=mysql_connect("localhost","root","14291530");
mysql_query("Use Examination;");
mysql_query("SET NAMES tis620");
mysql_query("SET collection_connection='tis620_thai_ci'");
$no= $_GET["no"];
$query="delete from examdata where no='$no';";
$result=mysql_query($query);
if($result)
{
$query="delete from examdata where no='$no'";
$result=mysql_query($query);
if($result)
{
echo "<center><b>ลบข้อสอบเรียบร้อยแล้ว<br>";
mysql_close($link);
}
else
{
echo "ไม่สามารถลบข้อสอบออกจากฐานข้อมูลได้";
}
?>
<?
}
?>
อยากให้มันส่งค่าที่เราเช็คบ๊อกให้มาลบอ่ะค่ะ
อันนี้โค๊ดหน้าแก้ไขค่ะ
<?
$link=mysql_connect("localhost","root","14291530");
mysql_query("Use Examination;");
mysql_query("SET NAMES tis620");
mysql_query("SET collection_connection='tis620_thai_ci'");
$no = $_GET["no"];
//$error=0;
$query = "SELECT * FROM examdata ";
$result = mysql_query($query);
$objResult= mysql_fetch_array($result,MYSQL_ASSOC);
$num_result = mysql_num_rows($result);
if($num_result == 0)
{
echo "ข้อสอบไม่ถูกต้องหรืออาจมีการลบข้อสอบไปแล้ว";
}
else
{
$update_query = "UPDATE examdata SET question='$question',choice1='$choice1',choice2='$choice2',choice3='$choice3',choice4='$choice4',answer='$answer' WHERE topicid=$no";
$update_result = mysql_query($update_query);
mysql_db_query($link,"SET NAMES tis620");
while ($objResult= mysql_fetch_array($result))
{
?>
จากโค๊ดนี้ต้องการให้โชว์เฉพาะที่เราเลือกเท่านั้นค่ะ แต่หน้านี้มันดันขึ้นมาทั้งหมดทั้งฐานข้อมูลเลยค่ะ
ช่วยหน่อยนะค่ะ พอดีโค๊ดก็ก๊อปเขามาความรู้ก็ไม่ค่อยมีเพิ่งหัดเขียนนะค่ะต้องส่งวันพุธนี้อ่ะค่ะช่วยหน่อยนะ
มีรูปด้วย



Tag : - - - -

|
|
 |
 |
 |
 |
Date :
2009-06-07 20:11:00 |
By :
JEX |
View :
1062 |
Reply :
7 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
วีธีการลบ ผมว่าลอง เช็คค่า $no ก่อนดีกว่า ว่ามันมีค่าหรือไม่ ที่มันไม่ลบใน db น่าจะมันไม่ได้ส่งค่ามาด้วยหรือเช็คไม่พบ
ทำไมตอนลบต้องลบ 2 ครั้งอะ ครั้งเดียวก็คงพอมั่ง
ส่วนที่ว่าแสดงเฉพาะข้อมูลที่เลือก ก็ให้ไปเช็ค คำตอบว่า เป็นคำตอบอะไร แล้วคอยไปแสดงค่าเฉพาะคำตอบนั้นอะ
ถ้า คำตอบ คือ C ให้แสดง choice 3
ถ้าคำตอบ คือ B ให้แสดง choice 2
ประมาณนี้ครับ
|
 |
 |
 |
 |
Date :
2009-06-08 09:32:30 |
By :
ail2geal2 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คืองี้ค่ะ
หน้าแรกเนี่ยให้แสดงข้อมูลของข้อสอบทั้งหมดซึ่งหน้านี้อาจารย์จะสามารถเข้าได้แค่คนเดียว
หากถ้าคลิกตรง เช็คบ๊อกแล้วให้ทำการลบข้อมูลที่เลือก แล้วหากคลิกตรงหัวข้อคำถามก็จะสามารถลิงค์เข้าไปแก้ไขข้อมูลได้ซึ่งที่ต้องการคือต้องการให้ขึ้นเฉพาะที่เลือกแก้ไขเท่านั้น
แต่ที่ทำได้ตอนนี้คือมันขึ้นทุกข้อเลยค่ะ ส่วนค่า $no นั้นเป็น Autonumber ค่ะ
ยังไงลองช่วยดูให้อีกทีนะค่ะ
|
 |
 |
 |
 |
Date :
2009-06-08 10:02:01 |
By :
Nicorobin |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เข้าใจแล้วครับ งั้น คุณก็เอา id ของข้อสอบมาใส่ที่ check box เวลาคุณเลือก check box อันไหน มันก็จะเก็บค่า id ของข้อสอบมาด้วย ดังนั้นมันจึโชว์เฉพาะที่เราเลือก
|
 |
 |
 |
 |
Date :
2009-06-08 10:07:40 |
By :
nongjen |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ใส่ยังไงค่ะ ถ้าใส่ตรง values ก็ใส่แล้วอ่ะค่ะ
value=<?=$objResult["no"];?>
|
 |
 |
 |
 |
Date :
2009-06-08 10:23:12 |
By :
Nicorobin |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองเปลี่ยนตัวแปลดูนะ เชคบ๊อก เป็น $testID[]
ตรวจสอบค่า id ของข้อสอบก่อนเลยครับ แล้วตอน Query เพื่อที่จะแสดงหน้าที่ ก็ select ตัวแปล check[$i] ตำแหน่งที่เลือกไว้
|
 |
 |
 |
 |
Date :
2009-06-08 11:20:22 |
By :
nongjen |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ช่วยอธิบายให้เข้าใจมากกว่านี้ได้ไหมค่ะ
แบบว่าเพิ่งหัดเขียนอ่ะค่ะงง รบกวนหน่อยนะค่ะ
|
 |
 |
 |
 |
Date :
2009-06-08 20:14:23 |
By :
Nicorobin |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แก้ได้แล้วค่ะ แต่ยังติดที่หน้าแก้ไขอยู่เลยอ่ะค่ะ พี่ ๆ ช่วยดูให้หน่อยนะค่ะ
|
 |
 |
 |
 |
Date :
2009-06-08 20:36:24 |
By :
Nicorobin |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 02
|