ช่วยแก้โค้ดทีครับ ผมฝึก PHP อยู่ ไม่เข้าใจ Error นี้ครับ
Code (PHP)
ตัวที่ error
Warning: mysql_result(): Unable to jump to row 0 on MySQL result index 5 in C:\AppServ\www\mg_webboard\board_home.php on line 42
Warning: mysql_result(): Unable to jump to row 0 on MySQL result index 5 in C:\AppServ\www\mg_webboard\board_home.php on line 43
Warning: mysql_result(): Unable to jump to row 0 on MySQL result index 5 in C:\AppServ\www\mg_webboard\board_home.php on line 44
CODE
<? include "connDB.php";
if($submit=="Add"){
// สร้างรหัสใหม่
$new_id =mysql_result(mysql_query("Select Max(board1_id)+1 as MaxID from board1"),0,"MaxID");
if($new_id==''){
$board1_id="00001";
}else{
$board1_id=sprintf("%05d",$new_id);
}
$sql="Insert Into board1 Set board_id='".$board_id."',board1_id='".$board1_id."',member_id='".$user_id1."',board1_title='".$board1_title."',board1_detail='".$board1_detail."',board1_datetime='".date("Y-m-d H:i:s")."',board1_status='No',board1_mud='No',board1_views='0',last_post='".date("Y-m-d H:i:s")."' ";
//echo $sql;
mysql_query($sql);
// ไปหน้าสุดท้าย อัตโนมัติ
?>
<script language="JavaScript">window.location.href = "board_home.php?board_id=<?=$board_id?>&action=Detail&post_id=<?=$board1_id?>&page2=1";</script>
<?
}elseif($submit=="Update"){
if($update_mud!="") mysql_query("Update board1 Set board1_mud='".$update_mud."' Where board1_id='".$post_id."' ");
if($update_status!="") mysql_query("Update board1 Set board1_status='".$update_status."' Where board1_id='".$post_id."' ");
}elseif($submit=="Delete" && $action2==""){
mysql_query("Delete from board2 Where board1_id='".$post_id."' ");
mysql_query("Delete from board1 Where board1_id='".$post_id."' ");
}elseif($submit=="Edit" && $board1_title!=""){
$board1_detail=$board1_detail."<br><em><< แก้ไขครั้งสุดท้าย เมื่อ ".date("Y-m-d H:i:s").">></em>";
$sql="Update board1 Set board1_title='".$board1_title."',board1_detail='".$board1_detail."' Where board1_id='".$post_id."'";
//echo $sql;
mysql_query($sql);
// ไปหน้าสุดท้าย อัตโนมัติ
?>
<script language="JavaScript">window.location.href = "board_home.php?board_id=<?=$board_id?>&action=Detail&post_id=<?=$post_id?>&page2=1";</script>
<?
}
?>
<?
$sql="Select board.*,board_group.board_group_name from board,board_group Where board.board_group_id=board_group.board_group_id and board.board_id='".$board_id."'";
//echo $sql;
$rst=mysql_query($sql);
$board_group_name=mysql_result($rst,0,"board_group_name");
$board_name=mysql_result($rst,0,"board_name");
$board_detail=mysql_result($rst,0,"board_detail");
if($post_id!=""){
$sql="Select * from board1 Where board1_id='".$post_id."' ";
$rst=mysql_query($sql);
$board1_title=mysql_result($rst,0,"board1_title");
}
?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="css.css">
<title><?=$web_title;?> <? if($post_id==""){ echo $board_name; }else{ echo $board1_title;}?></title>
<meta name="description" content="<?=$web_title2?>">
<body topmargin="0">
<? include "Menu_head.php"?>
<table width="980" align="center" style="border-bottom:2px; border-bottom-style: double; ">
<tr style="font-weight:bold; color:#FFFFFF; ">
<td width="832">
<a href="./" title="หน้าแรกเว็บ หวยหุ้น ดอทคอม">หน้าแรก</a> <img src="picture/next.jpg" width="12" height="12" align="baseline">
<a href="<?=ereg_replace(" ","-",$board_name)."_".$board_id?>.html" title="<?=$board_detail?>"><?=$board_name;?></a>
<? if($action=="Add") echo ' <img src="picture/next.jpg" width="12" height="12" align="baseline"> <a href="">เริ่มหัวข้อใหม่</a>';?>
<? if($post_id!=""){?>
<img src="picture/next.jpg" width="12" height="12" align="baseline"><a href="<?=ereg_replace(" ","-",$board1_title)."_".$board_id."_".$post_id?>_Detail.html" title="<?=$board1_title?>"><?=$board1_title?></a>
<? }?>
</td>
<td width="136" align="right" style="padding-right:5px; "><? if($user_id1!=""){?><img src="images/add.jpg" width="14" height="14"> <a href="board_home.php?board_id=<?=$board_id?>&action=Add">เริ่มหัวข้อใหม่</a><? }?></td>
</tr>
</table>
<? if($action==""){ // ดูหน้ารวมกระทู้?>
<table width="980" align="center">
<?
$sql="Select * from board1 Where board_id='".$board_id."' Order By board1_mud desc,last_post DESC";
//echo $sql;
$rst_temp=mysql_query($sql);
if(mysql_num_rows($rst_temp)==null){ // ถ้าไม่มีกระทู้
?>
<tr>
<td>
<table width="980">
<tr style="font-weight:bold;">
<td width="741"> <span style="font-size:18px; padding-left:40px; ">ยังไม่มีกระทู้ในหมวดนี้</span></td>
<td width="227" align="center"><span style="font-size:18px; ">0 กระทู้</span><br><span style="font-size:18px; ">0 หัวข้อ</span></td>
</tr>
</table>
</td>
</tr>
<? }else{ // ถ้ามีกระทู้ ?>
<tr>
<td>
<?
//$sql="Select * from board1 Where board_id='".$board_id ."' Order By last_post DESC";
$rst_show=mysql_query($sql);
while($arr2 = mysql_fetch_array($rst_show)){
$board1_lock =$arr2['board1_status'];
$board1_mud =$arr2['board1_mud'];
?>
<table width="100%" class="text_style" style="border-bottom:1px; border-bottom-style:dashed; " align="center">
<tr>
<td width="33" style="padding:0px 5px 0px 5px;"><img src="picture/new_topic.jpg" width="24" height="24"></td>
<td width="489" height="50" style="padding:0px 5px 0px 5px;">
<a href="<?=ereg_replace(" ","-",$arr2['board1_title'])."_".$arr2['board_id']."_".$arr2['board1_id']?>_Detail.html" title="<?=$arr2['board1_title']?>"><b><?=$arr2['board1_title']?></b></a><br>
โดย
<b><?=mysql_result(mysql_query("Select * from user Where user_id='".$arr2['member_id']."' "),0,"user_name")?></b> เมื่อ <?=$arr2['board1_datetime']?> </td>
<td width="42" style="padding:10px10px; text-align:center">
<?
if($board1_lock=="Yes")echo '<img src="images/lock.gif" border="0">';
if($board1_mud=="Yes")echo '<img src="images/stick.gif" border="0">';
?>
</td>
<td width="165" align="center">
อ่าน <b><?=mysql_result(mysql_query("Select * from board1 Where board1_id='".$arr2['board1_id']."' "),0,"board1_views")?></b> /
ตอบ <b><?=mysql_result(mysql_query("Select Count(board1_id) as ctotal from board2 Where board1_id='".$arr2['board1_id']."' "),0,"ctotal")?></b>
</td>
<td width="177" style="padding:5px 5px; ">
<?
$x=mysql_num_rows(mysql_query("Select * from board2 Where board1_id='".$arr2['board1_id']."' "));
if($x!=NULL){ // แสดงว่ามีกระทู้ และมีคนตอบกระทู้
$member_id=mysql_result(mysql_query("Select * from board2 Where board1_id='".$arr2['board1_id']."' Order By board2_id DESC"),0,"member_id");
$member_name=mysql_result(mysql_query("Select * from user Where user_id='".$member_id."' "),0,"user_name");
$last_post=mysql_result(mysql_query("Select * from board2 Where board1_id='".$arr2['board1_id']."' Order By board2_id DESC"),0,"board2_datetime");
?>
ตอบล่าสุด โดย <b><?=$member_name?></b><br>
เมื่อ <?=$last_post?>
<? }else{ echo "หัวข้อนี้ยังไม่มีความคิดเห็น";}?>
</td>
<td width="46" align="center">
<?
$sql_2="Select * from board2 Where board1_id='".$arr2['board1_id']."' Order By board2_id ASC";
$Total_1=mysql_num_rows(mysql_query($sql_2));
$Total_page=ceil($Total_1/$Pagelimit_board);
if($Total_page==0) $Total_page=1;
?>
<a href="<?=ereg_replace(" ","-",$arr2['board1_title'])."_".$arr2['board_id']."_".$arr2['board1_id']?>_Detail_<?=$Total_page?>.html" title="<?=$arr2['board1_title']?>"><img src="images/last_post.gif" width="20" height="20" border="0"></a> </td>
</tr>
</table>
<? }?>
</td>
</tr>
<? }?>
</table>
<? } //end if action?>
<? if($action=="Add"){?>
<script language="JavaScript">
function Check_txt_post(){
if(document.getElementById('board1_title').value==""){
alert("กรุณาระบุ หัวข้อ หรือ ชื่อเรื่อง ด้วยครับ");
document.getElementById('board1_title').focus();
return false;
}
/*
if(document.getElementById('board1_detail').value.length<=10 ){
alert("กรุณาระบุ รายละเอียด ด้วยครับ");
document.getElementById('board1_detail').focus();
return false;
}
if(document.getElementById('board1_detail').value.length<=20){
alert("กรุณาระบุ รายละเอียดสั้นเกินไป ครับ");
document.getElementById('board1_detail').focus();
return false;
}
*/
}
</script>
<script src="nicEdit.js" type="text/javascript"></script>
<script type="text/javascript">
<!--
bkLib.onDomLoaded(function() {
new nicEditor({buttonList : ['bold','italic','underline','ol','ul','fontSize','image','upload','link','unlink','forecolor','xhtml','smile']}).panelInstance('board1_detail');
});
//-->
</script>
<form action="board_home.php?board_id=<?=$board_id?>&action=<?=$action?>&submit=Add" method="post" onSubmit="return Check_txt_post()" >
<table width="980" align="center" class="table_border">
<tr>
<td height="41" colspan="2" align="center" class="h_text"><img src="images/add.jpg" width="15" height="17"> เริ่มหัวข้อใหม่ เปิดประเด็นสนทนา กรุณาใช้ภาษาไทยให้ถูกต้องและสุภาพด้วยนะค่ะ <img src="images/add.jpg" width="15" height="17"></td>
</tr>
<tr>
<td width="224" align="right" class="text_style"><b>หัวข้อ :</b> </td>
<td width="744"><input name="board1_title" type="text" id="board1_title" size="70" maxlength="200" ></td>
</tr>
<tr>
<td valign="top" align="right" class="text_style">
<b>รายละเอียด :</b>
<br><br>
<div align="left">
<ul >
<li>สามารถจัดรูปแบบตัวหนังสือ</li>
<li>เปลี่ยนขนาดของตัวหนังสือ</li>
<li>ใส่สีให้กับตัวหนังสือ</li>
<li>ใส่รูปภาพอ้างอิง</li>
<li>ใส่ลิงค์ให้กับข้อความ</li>
<li>หลากหลายไอคอนแสดงอารมณ์</li>
<li>และใส่โค้ดต่าง ๆ เช่น VDO ฯลฯ </li>
</ul>
</div> </td>
<td bgcolor="#FFFFFF"><textarea name="board1_detail" cols="60" id="board1_detail" style="height:250px; width:680px;text-align:left; left:auto;"></textarea></td>
</tr>
<tr>
<td height="79"> </td>
<td><input name="Submit3" type="submit" class="h_text" value=" ตั้งกระทู้ " >
<input name="Submit22" type="submit" class="h_text" onClick="window.location.href ='board_home.php?board_id=<?=$board_id?>&submit=';return false;" value=" ยกเลิก "></td>
</tr>
</table>
</form>
<? }?>
<? if($action=="Edit"){?>
<script language="JavaScript">
function chkdel(){
if(confirm(' กรุณายืนยันการลบอีกครั้ง !!! ')){
return true;
}else{
return false;
}
}
function Check_txt_comment(){
if(document.getElementById('board1_title').value==""){
alert("กรุณาระบุ หัวข้อ ด้วยครับ");
document.getElementById('board1_title').focus();
return false;
}
/*
if(document.getElementById('board1_detail').value.length<=5 ){
alert("กรุณาระบุ รายละเอียด ด้วยครับ");
document.getElementById('board1_detail').focus();
return false;
}
if(document.getElementById('board1_detail').value.length<=20){
alert("กรุณาระบุ รายละเอียดสั้นเกินไป ครับ");
document.getElementById('board1_detail').focus();
return false;
}
*/
}
</script>
<script src="nicEdit.js" type="text/javascript"></script>
<script type="text/javascript">
<!--
bkLib.onDomLoaded(function() {
new nicEditor({buttonList : ['bold','italic','underline','ol','ul','fontSize','image','upload','link','unlink','forecolor','xhtml','smile']}).panelInstance('board1_detail');
});
//-->
</script>
<form action="board_home.php?board_id=<?=$board_id?>&post_id=<?=$post_id?>&action=<?=$action?>&submit=Edit" method="post">
<table width="980" align="center" class="table_border">
<tr>
<td height="41" colspan="2" align="center" class="h_text"><img src="images/add.jpg" width="15" height="17"> เริ่มหัวข้อใหม่ เปิดประเด็นสนทนา กรุณาใช้ภาษาไทยให้ถูกต้องและสุภาพด้วยนะค่ะ <img src="images/add.jpg" width="15" height="17"></td>
</tr>
<tr>
<td width="224" align="right" class="text_style"><b>หัวข้อ :</b> </td>
<td width="744"><input name="board1_title" type="text" id="board1_title" size="70" maxlength="200" <? if($action=="Edit"){echo 'value="'.mysql_result(mysql_query("Select * from board1 Where board1_id='".$post_id."' "),0,"board1_title").'"';}?>></td>
</tr>
<tr>
<td valign="top" align="right" class="text_style">
<b>รายละเอียด :</b>
<br><br>
<div align="left">
<ul >
<li>สามารถจัดรูปแบบตัวหนังสือ</li>
<li>เปลี่ยนขนาดของตัวหนังสือ</li>
<li>ใส่สีให้กับตัวหนังสือ</li>
<li>ใส่รูปภาพอ้างอิง</li>
<li>ใส่ลิงค์ให้กับข้อความ</li>
<li>หลากหลายไอคอนแสดงอารมณ์</li>
<li>และใส่โค้ดต่าง ๆ เช่น VDO ฯลฯ </li>
</ul>
</div>
</td>
<td bgcolor="#FFFFFF">
<textarea name="board1_detail" cols="60" id="board1_detail" style="height:250px; width:680px;text-align:left; left:auto;">
<? if($action=="Edit")echo mysql_result(mysql_query("Select * from board1 Where board1_id='".$post_id."' "),0,"board1_detail");?>
</textarea>
</td>
</tr>
<tr>
<td height="79"> </td>
<td>
<input name="Submit3" type="submit" class="h_text" value=" ตั้งกระทู้ " >
<input name="Submit22" type="submit" class="h_text" onClick="window.location.href ='board_home.php?board_id=<?=$board_id?>&submit=';return false;" value=" ยกเลิก ">
</td>
</tr>
</table>
</form>
<? }?>
<? //if($action=="Detail" && ($page2=="" or $page2==1)){
if($action=="Detail" ){
$sql="Update board1 Set board1_views=board1_views+1 Where board1_id='".$post_id."' ";
mysql_query($sql);
$sql="Select * from board1 Where board1_id='".$post_id."' ";
$rst_show=mysql_query($sql);
$board1_title =mysql_result($rst_show,0,"board1_title");
$board1_detail =mysql_result($rst_show,0,"board1_detail");
$member_id =mysql_result($rst_show,0,"member_id");
$board1_datetime =mysql_result($rst_show,0,"board1_datetime");
$board1_views =mysql_result($rst_show,0,"board1_views");
$board1_lock =mysql_result($rst_show,0,"board1_status");
$board1_mud =mysql_result($rst_show,0,"board1_mud");
$comment_name=mysql_result(mysql_query("Select * from user Where user_id='".$member_id."' "),0,"user_name");
$user_picture=mysql_result(mysql_query("Select * from user Where user_id='".$member_id."' "),0,"user_picture");
$user_id=mysql_result(mysql_query("Select * from user Where user_id='".$member_id."' "),0,"user_id");
?>
<br>
<? if($action=="Detail" && ($page2=="" or $page2==1)){?>
<table width="980" border="0" align="center" cellpadding="0" cellspacing="0" class="table_border">
<tbody>
<tr height="30" class="text_style"">
<th height="29" colspan="3" align="center" class="h_text" style="border-right:1px; border-right-style:dashed; ">:: <?=$board1_title?> :: </th>
</tr>
<tr height="30" class="text_style">
<th width="180" align="center" class="border_head" style="border-right:1px; border-right-style:dashed; " >ผู้ก่อตั้งกระทู้นี้</th>
<th width="519" height="29" align="left" class="border_head" style="padding-left:10px; ">เมื่อ <?=$board1_datetime?></th>
<th width="289" align="right" class="border_head" style="padding-right:10px;">
<? if($member_id==$user_id1){?>
<a href="board_home.php?board_id=<?=$board_id?>&post_id=<?=$post_id?>&action=Edit" title="แก้ไขความเห็นนี้">Edit</a>
<? }?>...
</th>
</tr>
<tr>
<td colspan="3" class="dot_line_horizon" height="3"></td>
</tr>
<tr width="120" valign="top">
<td align="center" background="images/bg_table3.png" style="border-right:1px; border-right-style:dashed; "><?
if($user_picture==''){
$artist_sex="user_pic/1.png";
?>
<img src="<?=$artist_sex?>" width='100' height='100' border='0' title="สัตว์เลี้ยงของ <?=$comment_name?>">
<? }else{?>
<img src="user_pic/<?=$user_picture?>" width='100' height='100' border='0' title="สัตว์เลี้ยงของ <?=$comment_name?>">
<? }?><br>
<b style="color:#009900; "><?=$comment_name?></b> </td>
<td colspan="2" align="left" valign="top" background="images/bg_table3.png" style="padding:10px 10px;">
<div class="post"><?=$board1_detail?>
<br>
</div> </td>
</tr>
<tr>
<td height="3" align="center" style="border-right:1px; border-right-style:dashed;">
<? if($user_type=="Admin"){?>
<? if($board1_lock=="Yes"){?><a href="body.php?page=<?=$page?>&board_id=<?=$board_id?>&action=&submit=Update&post_id=<?=$post_id?>&update_status=No"><img src="images/lock_x.gif" border="0"></a><? }else{?><a href="body.php?page=<?=$page?>&board_id=<?=$board_id?>&action=&submit=Update&post_id=<?=$post_id?>&update_status=Yes"><img src="images/lock.gif" border="0"></a><? }?>
<? if($board1_mud=="Yes"){?><a href="body.php?page=<?=$page?>&board_id=<?=$board_id?>&action=&submit=Update&post_id=<?=$post_id?>&update_mud=No"><img src="images/stick_x.gif" border="0"></a><? }else{?><a href="body.php?page=<?=$page?>&board_id=<?=$board_id?>&action=&submit=Update&post_id=<?=$post_id?>&update_mud=Yes"><img src="images/stick.gif" border="0"></a><? }?>
<a href="body.php?page=<?=$page?>&board_id=<?=$board_id?>&action=&submit=Delete&post_id=<?=$post_id?>" OnClick="return chkdel();"><img src="images/del.jpg" border="0" title="ลบกระทู้นี้"></a>
<? }?> </td>
<td colspan="2" align="right" style="padding:5px 5px;">
<? if($user_id!=""){?>
<img src="images/del.jpg" width="9" height="9" border="0"> <a href="#" onClick="MM_openBrWindow('delete_board1.php?board1_id=<?=$post_id?>&action=confirm&member_id=<?=$user_id?>&p=board1','480','400'); return false" title="แจ้งลบคอมเม้นท์นี้">แจ้งลบคอมเม้นท์นี้</a>
<? }?> </td>
</tr>
</tbody>
</table>
<? }?>
<? include "board_comment.php"; ?>
<? }?>
<? include "Menu_buttom.php"?>
</body>
ฝากด้วยครับ งงมาก Tag : PHP, MySQL, JavaScript, Appserv
Date :
2019-01-14 20:54:31
By :
thisbook
View :
814
Reply :
3
มันผิดตั้งแต่ SQL แล้วครับ
Select board.*,board_group.board_group_name
from board,board_group
Where
board.board_group_id=board_group.board_group_id and board.board_id= x
Select board.*,board_group.board_group_name
from board
inner join board_group
ON board.board_group_id=board_group.board_group_id
where board.board_id= xxxx
Date :
2019-01-16 13:26:42
By :
mee079
Load balance : Server 03