รบกวนดูให้หน่อยค่ะ Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource
คราวหลังเอาโค๊ดมาแปะตรงๆ แล้วครอบด้วย Php tag นะครับ
ดูแล้วเหมือนจะปิดวงเล็บผิดที่ มันอาจะไม่เข้า If มันเลยไม่มี $sql_show_type
Date :
2011-04-27 12:04:39
By :
PlaKriM
Code (PHP)
<?
session_start();
ob_start();
require_once('../Connections/panfan.php');
?>
<script language="Javascript1.2"><!-- // load htmlarea
_editor_url = ""; // URL to htmlarea files
var win_ie_ver = parseFloat(navigator.appVersion.split("MSIE")[1]);
if (navigator.userAgent.indexOf('Mac') >= 0) { win_ie_ver = 0; }
if (navigator.userAgent.indexOf('Windows CE') >= 0) { win_ie_ver = 0; }
if (navigator.userAgent.indexOf('Opera') >= 0) { win_ie_ver = 0; }
if (win_ie_ver >= 5.5) {
document.write('<scr' + 'ipt src="' +_editor_url+ 'editor.js"');
document.write(' language="Javascript1.2"></scr' + 'ipt>');
} else { document.write('<scr'+'ipt>function editor_generate() { return false; }</scr'+'ipt>'); }
// --></script>
<script type="text/JavaScript">
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}
//-->
</script>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874">
<link href="../css.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.style1 {color: #333333}
.style4 {color: #FFFFFF}
.style5 {color: #FFFFFF; font-weight: bold;}
.style6 {font-weight: bold}
-->
</style>
<p align="center"><font size="2" face="MS Sans Serif, Tahoma, sans-serif">
<?
$dd=date("Ymdhis");
if($funtion=='add'){
$a_pm = sprintf("INSERT INTO promotion (id_pm, type_ref, id_type, head, head_en, detail, detail_en) VALUES (0,%s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['type_ref'], "text"),
GetSQLValueString($_POST['id_type'], "int"),
GetSQLValueString($_POST['head'], "text"),
GetSQLValueString($_POST['head_en'], "text"),
GetSQLValueString($_POST['detail'], "text"),
GetSQLValueString($_POST['detail_en'], "text"));
$result1 = mysql_query($a_pm) or die(mysql_error());
$sql=mysql_query("select * from promotion where head_en='".$_POST['head_en']."' order by id_pm desc");
$result2=mysql_fetch_array($sql);
if($photo<>"") {$up_photo=img_upload($_FILES['photo'],$result2["id_pm"],"../imghotel/promotion/");}
$sql_photo = "update promotion set
photo='$up_photo'
where id_pm=".$result2["id_pm"]."";
$query_photo=mysql_query($sql_photo);
echo"<br><br>ทำการเพิ่มข้อมูลโปรโมชั่นแล้วครับ<meta http-equiv=refresh content=0;URL=?page_a=$page_a&id=$id >";
} else if($funtion=='edit'){
if($photo<>"") {unlink("../imghotel/promotion/".$photoname.""); $photoname=img_upload($_FILES['photo'],$_GET['id'],"../imghotel/promotion/");}
$sql_photo="update promotion set
photo='$photoname'
where id_pm=".$_GET['id']."";
$photo_query=mysql_query($sql_photo);
$e_pm = sprintf("UPDATE promotion SET `type_ref`=%s,`id_type`=%s,`head`=%s, `head_en`=%s,`detail`=%s,`detail_en`=%s WHERE id_pm=%s",
GetSQLValueString($_POST['type_ref'], "text"),
GetSQLValueString($_POST['id_type'], "int"),
GetSQLValueString($_POST['head'], "text"),
GetSQLValueString($_POST['head_en'], "text"),
GetSQLValueString($_POST['detail'], "text"),
GetSQLValueString($_POST['detail_en'], "text"),
GetSQLValueString($_GET['id'], "int"));
$result1 = mysql_query($e_pm) or die(mysql_error());
echo"<br><br>ทำการแก้ไขข้อมูลโปรโมชั่นแล้วครับ <meta http-equiv=refresh content=0;URL=?page_a=$page_a&id=$id >";
}
else if($funtion=='dele'){
if($photo<>"") {unlink("../imghotel/promotion/".$photo.""); }
$sql="delete from promotion where id_pm=$id";
$db_query=mysql_query($sql);
print "<br><br>ทำการลบข้อมูลแล้วครับ<meta http-equiv=refresh content=0;URL=?page_a=$page_a&id=$id >";
?>
</span></font></p>
<div align="left"><font size="2" face="MS Sans Serif, Tahoma, sans-serif">
<? } else if($funtion=='form'){
?>
</p>
</div>
<span class="txtblue01"><strong>ระบบจัดการโปรโมชั่น <?
echo "$type_ref" ?></strong> <br />
<br>
</div>
</span>
<table width="98%" border="0" cellpadding="2" cellspacing="1">
<?
if($f_edit=='f_edit')
{
$sql=mysql_query("select * from promotion where id_pm='$id'");
$result2=mysql_fetch_array($sql);
echo"<form name=\"form2\" method=\"post\" action=\"?page_a=$page_a&funtion=edit&id=".$result2['id_pm']."\" enctype=\"multipart/form-data\">";}
else
{echo"<form name=\"form2\" method=\"post\" action=\"?page_a=$page_a&funtion=add&id=".$id."\" enctype=\"multipart/form-data\">";}
?>
<tr bgcolor="#DFDFDF">
<td height="26" colspan="2" bgcolor="#73B3F2" class="txt12gray">
<div align="center" class="style5"><font size="2" face="MS Sans Serif, Tahoma, sans-serif"><span class="style3">
<?
if($f_edit=='f_edit') {echo"แก้ไขโปรโมชั่น" ;}
else {echo "เพิ่มโปรโมชั่น";}
?>
</span></font></div></td>
</tr>
<?
?>
<tr>
<td align="center" valign="middle" bgcolor="#3399FF" class="txt13yellow">โปรโมชั่น</td>
<td bgcolor=""><div align="left"><font size="2" face="MS Sans Serif, Tahoma, sans-serif">
<label></label>
<? if($type_ref==a_hotel) {
$sql_show_type=mysql_query ("select * from hotel where pro='1' ");
}
if($type_ref==b_domestic) {
$sql_show_type=mysql_query ("select * from domestic where pro='1' ");
}
if($type_ref==c_outbound) {
$sql_show_type=mysql_query ("select * from outbound where pro='1' ");
}
if($type_ref==strip) {
$sql_show_type=mysql_query ("select * from strip where pro='1' ");
}
if($type_ref==sight_pax) {
$sql_show_type=mysql_query ("select * from sight_pax where pro='1' ");
}
if($type_ref==sight_sprice) {
$sql_show_type=mysql_query ("select * from sight_sprice where pro='1' ");
}
if($f_edit=='f_edit') {
$type_ref="".$result2['type_ref']."";
$sql_show_type=mysql_query ("select * from promotion where type_ref =".$type_ref['type_ref']." order by name");}
$num_rows_type=mysql_num_rows($sql_show_type);
$no_type=1;
?>
<select name="id_type">
<?
while($type=mysql_fetch_array($sql_show_type)){
if($no_type==1){
?>
<option value="">--- กรุณาเลือกโปรโมชั่น ---</option>
<?php }
if($type_ref==a_hotel) {
$id_type = $type["id_hotel"];
}
if($type_ref==b_domestic) {
$id_type = $type["id_domes"];
}
if($type_ref==c_outbound) {
$id_type = $type["id_out"];
}
if($type_ref==strip) {
$id_type = $type["id_strip"];
}
if($type_ref==sight_pax) {
$id_type = $type["id_ssight2"];
}
if($type_ref==sight_sprice) {
$id_type = $type["id_ssight"];
}
$name_type = $type["name"];
?>
<option value= "<?php echo "$id_type";?>"
<?php if($f_edit=='f_edit') {
if($id_type==$result2[id_type]) { echo "selected"; } }
?>> <? echo "$name_type"; ?></option>
<?php $no_type++; } ?>
</select>
</font></div>
<input type="hidden" name="type_ref" id="type_ref" value="<? echo "".$type_ref."";?>">
<? if($f_edit=='f_edit') { ?> <input type="hidden" name="type_ref" id="type_ref" value="<? echo "".$result2['type_ref']."";?>"> <? } ?> </td>
</tr>
<tr>
<td align="center" valign="middle" bgcolor="#3399FF" class="txt13yellow">รุปภาพ</td>
<td colspan="3" bgcolor=""><div align="left"><font size="2" face="MS Sans Serif, Tahoma, sans-serif">
<input name="photo" type="file" id="photo" />
<input name="type_ref" type="hidden" id="type_ref" value="<? echo"".$type_ref."";?>" />
ขนาด 57 X 57<br />
<? if($f_edit=='f_edit') {?>
<img src="../imghotel/promotion/<? echo"".$result2['photo']."";?>" />
<input name="photoname" type="hidden" id="photoname" value="<? echo"".$result2['photo']."";?>" />
<input name="type_ref" type="hidden" id="type_ref" value="<? echo"".$result2['type_ref']."";?>" />
<? }?>
</font></div></td>
</tr>
<tr>
<td align="center" valign="middle" bgcolor="#3399FF" class="txt13yellow">หัวเรื่อง</td>
<td bgcolor=""><div align="left"><font size="2" face="MS Sans Serif, Tahoma, sans-serif">
<label> </label>
<textarea name="head" cols="60" rows="6" id="head"><?php if($f_edit=='f_edit') {echo"".$result2['head']."";}?>
</textarea>
<label>
<script language="javascript1.2">
editor_generate('detail');
</script>
</label>
</font></div></td>
</tr>
<tr>
<td align="center" valign="middle" bgcolor="#3399FF" class="txt13yellow">รายละเอียด</td>
<td bgcolor=""><div align="left"><font size="2" face="MS Sans Serif, Tahoma, sans-serif">
<label> </label>
<textarea name="detail" cols="60" rows="6" id="detail"><?php if($f_edit=='f_edit') {echo"".$result2['detail']."";}?>
</textarea>
<label>
<script language="javascript1.2">
editor_generate('detail');
</script>
</label>
</font></div></td>
</tr>
<tr>
<td width="13%" align="center" valign="middle" bgcolor="#3399FF" class="txt12Syellow">Head EN </td>
<td width="87%" bgcolor=""><div align="left"><font size="2" face="MS Sans Serif, Tahoma, sans-serif">
<textarea name="head_en" cols="60" rows="6" id="head_en"><?php if($f_edit=='f_edit') {echo"".$result2['head_en']."";}?>
</textarea>
<label>
<script language="javascript1.2">
editor_generate('detail_en');
</script>
</label>
</font></div></td>
</tr>
<tr>
<td width="13%" align="center" valign="middle" bgcolor="#3399FF" class="txt12Syellow">Detail EN</td>
<td width="87%" bgcolor=""><div align="left"><font size="2" face="MS Sans Serif, Tahoma, sans-serif">
<textarea name="detail_en" cols="60" rows="6" id="detail_en"><?php if($f_edit=='f_edit') {echo"".$result2['detail_en']."";}?>
</textarea>
<label>
<script language="javascript1.2">
editor_generate('detail_en');
</script>
</label>
</font></div></td>
</tr>
<tr bgcolor="#DFDFDF">
<td colspan="2" bgcolor="#73B3F2"><div align="center"> <font size="2" face="MS Sans Serif, Tahoma, sans-serif">
<?
if($f_edit=='f_edit') {echo"<input type=\"submit\" name=\"Submit\" value=\"แก้ไขโปรโมชั่น\">";}
else {echo"<input type=\"submit\" name=\"Submit\" value=\"เพิ่มโปรโมชั่น\">";}
?>
</font></div></td>
</tr>
<? echo"</form>"; ?>
</table>
<div align="left"><font size="2" face="MS Sans Serif, Tahoma, sans-serif"><br>
<? } else {?>
</p>
</div>
<span class="txtblue01"><strong>ระบบจัดการโปรโมชั่น</strong></span><br />
<br >
<?
?>
<table width="100%" border="0" cellpadding="2" cellspacing="1">
<form name="form1s"><tr>
<td colspan="4" bgcolor="#F0F8FF">
<font size="2" face="MS Sans Serif, Tahoma, sans-serif">
<div align="center" class="txt12gray style1"><font size="2" face="MS Sans Serif, Tahoma, sans-serif">
<select name="type_ref" onChange="MM_jumpMenu('parent',this,0)">
<option value="?page_a=<? echo $page_a; ?>"> ----------- เลือกประเภท -----------</option>
<option value="?page_a=<? echo $page_a;?>&type_ref=a_hotel"
<? if($type_ref=="a_hotel") { echo "selected"; }?>>Hotel</option>
<option value="?page_a=<? echo $page_a; ?>&type_ref=b_domestic"
<? if($type_ref=="b_domestic") { echo "selected"; }?>>Domestic Package</option>
<option value="?page_a=<? echo $page_a; ?>&type_ref=c_outbound"
<? if($type_ref=="c_outbound") { echo "selected"; }?>>Outbound Package</option>
<option value="?page_a=<? echo $page_a; ?>&type_ref=strip"
<? if($type_ref=="strip") { echo "selected"; }?>>Special Trip</option>
<option value="?page_a=<? echo $page_a; ?>&type_ref=sight_sprice"
<? if($type_ref=="sight_sprice") { echo "selected"; }?>>Sight Seeing - Saling Price</option>
<option value="?page_a=<? echo $page_a; ?>&type_ref=sight_pax"
<? if($type_ref=="sight_pax") { echo "selected"; }?>>Sight Seeing - Price/Pax</option>
</select>
</font>[ <a href="?page_a=<? echo "$page_a";?>">ดูทั้งหมด</a> ]</div> </tr>
</form>
<?
if($type_ref=="" ) {
$strSQL="select * from promotion order by id_pm desc";
} else {
$strSQL="select * from promotion where type_ref= '".$type_ref."' order by id_pm desc";
}
$Per_Page = 20;//จำนวนต่อหน้า
if ( !$Page )
$Page = 1;
$Prev_Page = $Page - 1;
$Next_Page = $Page + 1;
$resultg = mysql_query($strSQL);
$Page_start = ( $Per_Page * $Page ) - $Per_Page;
$Num_Rows = mysql_num_rows( $resultg );
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;
if ( ( $Page > $Num_Pages ) || ( $Page < 0 ) )
print "จำนวน $Page มากกว่า $Num_Pages";
$strSQL .= " LIMIT $Page_start, $Per_Page";
$allPage = ceil($Num_Rows/$Per_Page);
if(isset($_GET['Page'])){
$Page = $_GET['Page'];
$topage = $Page-1;
}else{
$topage = 0;
$Page = 1;
}
$linkpage = "<a href='".$_SERVER['PHP_SELF']."?Page=1&page_a=$page_a&id=$id' title='ไปหน้าแรก' class='txtorg12b'>[ Prev ]</a> ";
if($Page<6){
$i=1;
$allPage<11 ? $doLoop = $allPage : $doLoop = 11;
while($i<=$doLoop){
if($i==$Page){
$linkpage .= "<span class='box'><b>$i</b></span> ";
}else{
$linkpage .= "<a href='".$_SERVER['PHP_SELF']."?Page=$i&page_a=$page_a&id=$id' class='txtorg12b'>$i</a> ";
}
$i++;
}
}elseif( ($allPage-$Page) < 6){
$allPage<11 ? $start = 1 : $start = $allPage-10;
for($i=$start;$i<=$allPage;$i++){
if($i==$Page){
$linkpage .= "<span class='box'><b>$i</b></span> ";
}else{
$linkpage .= "<a href='".$_SERVER['PHP_SELF']."?$temp&Page=$i&page_a=$page_a&id=$id' class='txtorg12b'>$i</a> ";
}
}
}else{
for($i=$Page-5;$i<=$Page+5;$i++){
if($i==$Page){
$linkpage .= "<span class='box'><b>$i</b></span> ";
}else{
$linkpage .= "<a href='".$_SERVER['PHP_SELF']."?Page=$i&page_a=$page_a&id=$id' class='txtorg12b'>$i</a> ";
}
}
}
$linkpage .= "<a href='".$_SERVER['PHP_SELF']."?Page=$allPage&page_a=$page_a&id=$id' title='ไปหน้าสุดท้าย' class='txtorg12b'>[ Last ]</a>";
?>
<?
if($type_ref ==hotel){ $type=Hotel ;}
if($type_ref ==outbound){ $type=Outbound_Package;}
if($type_ref ==domestic){ $type=Domestic_Package;}
if($type_ref ==strip){ $type=Special_Trip;}
if($type_ref ==sight_pax){ $type=Sight_Seeing_Pax;}
if($type_ref ==sight_sprice){ $type=Sight_Seeing_Price;}
?>
<tr>
<td colspan="4" bgcolor="#F0F8FF"><div align="right" class="txt12gray"><? echo $linkpage;?></div></td>
</tr>
<tr>
<td colspan="4" bgcolor="#F0F8FF"><div align="left"><font size="2" face="MS Sans Serif, Tahoma, sans-serif">
<a href="?page_a=<? echo"$page_a";?>&type_ref=<? echo"$type_ref";?>&funtion=form" class="txt12gray style1"><strong><? if($_GET['type_ref']){ echo "+ เพิ่มโปรโมขั่น " ;}?><? echo "$type";?></strong></a></font></div>
<div align="left"></div></td>
</tr>
<? ?>
<tr>
<td width="880" bgcolor="#73B3F2"><div align="center" class="style4"><font size="2" face="MS Sans Serif, Tahoma, sans-serif"><strong><strong>โปรโมชั่น</strong></strong></font></div></td>
<td width="60" bgcolor="#006699"><div align="center" class="style4"><strong><font size="2" face="MS Sans Serif, Tahoma, sans-serif">แก้ไข</font></strong></div></td>
<td width="60" bgcolor="#006699"><div align="center" class="style4"><strong><font size="2" face="MS Sans Serif, Tahoma, sans-serif">ลบ</font></strong></div></td>
</tr>
<?
if($Num_Rows==0){
?>
<tr bgcolor="">
<td colspan="14" bgcolor="#FFFFCC"><div align="center"><font size="2" face="MS Sans Serif, Tahoma, sans-serif"><span class="style6">ยังไม่มีข้อมูลครับ</span></font></div></td>
</tr>
<?
} else { // แยก type
$sql_show = mysql_query( $strSQL);
while($result2 = mysql_fetch_array($sql_show)){
$sql_type=mysql_query("select * from promotion where id_pm='".$result2['id_pm']."'");
$num_rows_type=mysql_num_rows($sql_type);
if($num_rows_type == 0) {$dd = "";}
else {
$_type=mysql_fetch_array($sql_type);
$dd = $_type['type_ref'];
}
?>
<tr bgcolor="">
<td height="20" bgcolor="#F8F8F8" class="txtred12"><div align="left"><font size="2" face="MS Sans Serif, Tahoma, sans-serif">[ <? echo $dd;?> ] <? echo"".$result2['head']."";?></font></div></td>
<td width="60" bgcolor="#E8E8E8"><div align="center"><font size="2" face="MS Sans Serif, Tahoma, sans-serif"><span class="style6"><a href="?page_a=<? echo"$page_a";?>&funtion=form&f_edit=f_edit&id=<? echo"".$result2['id_pm']."";?>&type_ref=<? echo"".$result2['type_ref']."";?>">แก้ไข</a></span></font></div></td>
<td width="60" bgcolor="#E8E8E8"><div align="center"><font size="2" face="MS Sans Serif, Tahoma, sans-serif"><span class="style6"><a href="?page_a=<? echo"$page_a";?>&funtion=dele&id=<? echo"".$result2['id_pm']."";?>&photo=<? echo"".$result2['photo']."";?>">ลบ</a></span></font></div></td>
</tr>
<? }}?>
</table>
</div> <? }
mysql_close(); ?>
</body>
</html>
Date :
2011-04-27 12:58:48
By :
panfantour
โทดทีนะค่ะ
อันนี้แบบเต็ม ๆ อ่ะค่ะ รบกวนหน่อยนะค่ะ
Date :
2011-04-27 12:59:33
By :
panfantour
อย่างที่บอกน่าจะปิดผิดอยู่นะ
if($f_edit=='f_edit') {
$type_ref="".$result2['type_ref']."";
$sql_show_type=mysql_query ("select * from promotion where type_ref =".$type_ref['type_ref']." order by name");}
$num_rows_type=mysql_num_rows($sql_show_type);
$no_type=1;
Date :
2011-04-27 13:41:48
By :
PlaKriM
ลองแก้ดูแล้วอ่ะค่ะ แต่ก็ยังเหมือนเดิม หรือเป็นเพราะตัวแปรด้วยหรือเปล่าคือ
พอดีเพิ่งหัดทำอ่ะค่ะ เลยไม่ค่อยเก่งเท่าไหร่
Date :
2011-04-27 14:06:05
By :
panfantour
$sql_show_type=mysql_query ("select * from promotion where type_ref = '".$type_ref['type_ref']."' order by name");
ตรง '".$type_ref['type_ref']."' ใส่ ' ครอบทั้งสองฝั่ง ดูคับ
Date :
2011-04-27 14:44:28
By :
ไวยวิทย์
ลองทำแล้วอ่ะค่ะ คุณ Nico แต่ก็ยังเป็นเหมือนเดิมอ่ะค่ะ
พอดีหน้านี้ไม่ได้ทำเองด้วยค่ะ ทำต่อจากพี่อีกคนหนึ่งก็เลยงง ๆ อ่ะค่ะ
Date :
2011-04-27 16:28:42
By :
panfantour
น่าจะเกิดจากที่ Code (PHP)
if($f_edit=='f_edit') {
$type_ref="".$result2['type_ref']."";
$sql_show_type=mysql_query ("select * from promotion where type_ref =".$type_ref['type_ref']." order by name");}
$num_rows_type=mysql_num_rows($sql_show_type);
$no_type=1;
มันไม่ได้เข้าไปใน เงือ่นไข if คัรบ ทำให้ mysql_num_rows($sql_show_type) ตัวแปล $sql_show_type มันไม่มีค่าครับ ทำให้มันไม่สามารถหาค่าได้
แล้วพยายามอย่าใช้ตัวแปล $sql_show_type ตัวเดียวกันน่ะครับ เดียวจะสับสนเอาง่ายๆ
Date :
2011-04-27 19:58:48
By :
nut_ch31
Load balance : Server 02