สอบถามผู้รู้ code ค้นหาข้อมูลทำไมเมื่่อกดค้นหาแล้วไม่โชว์ข้อมูลค่ะ
Code (PHP)
<? include "../chksession.php"; ?>
<? include "../include/connect.php"; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/template.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>ระบบงานครุภัณฑ์ โครงการชลประทานสงขลา</title>
<!-- InstanceEndEditable -->
<link href="../css_style.css" rel="stylesheet" type="text/css" />
<!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->
</head>
<!-- InstanceBeginEditable name="head1" -->
<script language="javascript">
function popup(username){
var url="regis_user.php?username="+username;
window.open(url,'','width=350,height=250,left=80,right=80,top=80');//v2.0
}
</script>
<script language="javascript">
function popup1(username){
var url="edit_user.php?username="+username;
window.open(url,'','width=350,height=250,left=80,right=80,top=80');//v2.0
}
</script>
<!-- InstanceEndEditable -->
<body>
<table width="850" height="292" border="0" align="center" cellpadding="0" cellspacing="0" class="table_big">
<tr>
<td height="150" align="left" valign="top"><img src="../image/header.jpg" width="854" height="150" /></td>
</tr>
<tr bgcolor="#FFFFFF">
<td height="108" valign="top"><!-- InstanceBeginEditable name="EditRegion3" -->
<table width="850" height="319" border="0" cellpadding="0" cellspacing="0">
<tr>
<td valign="top"><table width="845" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="30"><? include ("menu_admin.php");?></td>
</tr>
</table>
<TABLE cellSpacing=0 cellPadding=0 width=700
align=center>
<TBODY>
<TR valign="top">
<TD><form name="form1" method="post" action="">
<div align="center">
<table width="300" border="1" align="center" cellpadding="0" cellspacing="0">
<tr bordercolor="#A10200">
<td width="300" bordercolor="" bgcolor="#FFFFFF"><table width="300" align="center" bgcolor="#FFFFFF">
<tr>
<td height="16" valign="top" bgcolor="#F0ECEB"><table width="780" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#F0ECEB" bgcolor="#F0ECEB">
<tr>
<td><table width="775" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#A0A7DE">
<tr bordercolor="#A0A7DE" bgcolor="#F0ECEB"> </tr>
<tr bordercolor="#A0A7DE" bgcolor="#F0ECEB"> </tr>
</table></td>
</tr>
<td height="71"><table width="780" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#F0ECEB" bgcolor="#E8E8E8">
<td height="46">
<? if($Search=="search"){
$TxtSearch=trim($TxtSearch);
if(isset($TxtSearch)){
if($page==null)$page=1;
$sql="SELECT * FROM tb_login WHERE ((name LIKE '%$TxtSearch%') or (lastname LIKE '%$TxtSearch%') or (class LIKE '%$TxtSearch%')) ORDER BY id ASC;";
$result=mysql_query($sql);
$rowsOfPage=mysql_num_rows($result);
$sql="SELECT * FROM tb_login WHERE ((name LIKE '%$TxtSearch%') or (lastname LIKE '%$TxtSearch%') or (class LIKE '%$TxtSearch%')) ORDER BY id ASC LIMIT ".(($page-1)*20).",20";
$result=mysql_query($sql);
$rows=mysql_num_rows($result);
}
} else{
if($page==null)$page=1;
$sql="SELECT * FROM tb_login";
$result=mysql_query($sql);
$rowsOfPage=mysql_num_rows($result);
$sql="SELECT * FROM tb_login LIMIT ".(($page-1)*20).",20";
$result=mysql_query($sql);
$rows=mysql_num_rows($result);
}
?>
<table width="780" border="1" align="center" bordercolor="#F0ECEB">
<td bgcolor="#F0ECEB">
<table width="780" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td bgcolor="#F0ECEB"><div align="right"><font color="#000000" size="2" face="MS Sans Serif, Tahoma, sans-serif" class="content">ค้นหาจาก(ชื่อ-สกุล-ระดับผู้ใช้)</font><span class="style14">::</span>
<!--<select name="select">
<option value="name">ชื่อ</option>
<option value="lastname">สกุล</option>
<option value="class" selected="selected">ระดับผู้ใช้</option>
</select>-->
<input name="TxtSearch" type="text" id="TxtSearch" value="<? echo $TxtSearch;?>" onClick="javascript:txt.value='';">
<input name="Submit" type="submit" id="Submit" value="ค้นหา">
<input name="Search" type="hidden" id="Search" value="search">
</div></td>
</tr>
<tr>
<td bgcolor="#F0ECEB"><div align="right">
<? if($TxtSearch!=""){ ?>
<font face="MS Sans Serif, Tahoma, sans-serif" color="#990000" size="2">ผลการสืบค้นมีทั้งหมด <? echo $rows;?> รายการ</font>
<? } else{?>
<? }?>
</div>
<table width="800" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#F0ECEB">
<tr bgcolor="#3366FF">
<td width="808" height="133"><table width="752" height="130" border="1" align="center" cellpadding="1" cellspacing="1" bordercolor="#3366FF" bgcolor="#F0ECEB">
<tr bgcolor="#3366FF">
<td height="23" colspan="7" align="center" bgcolor="#F0ECEB"><table width="800" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="125" align="left" valign="top" bgcolor="#F0ECEB"><font color="#0000FF" size="2" face="MS Sans Serif, Tahoma, sans-serif"><a href="#" onClick="popup('<? echo $arr_data["username"];?>');"><img src="../image/insert_mem2.jpg" width="125" height="30" border="0"></a><br></font></td>
<td width="675" align="center" bgcolor="#A10200"> </td>
</tr>
</table></td>
</tr>
<tr bgcolor="#3366FF">
<td width="7%" height="23" align="center" bgcolor="#A10200"><font size="2" face="MS Sans Serif, Tahoma, sans-serif" color="#FFFFFF" >ลำดับที่</font></td>
<td width="45%" align="center" bgcolor="#A10200"><span class="style1"><font size="2" face="MS Sans Serif, Tahoma, sans-serif" color="#FFFFFF">ชื่อ - สกุล </font></span></td>
<td width="27%" align="center" bgcolor="#A10200"><font size="2" face="MS Sans Serif, Tahoma, sans-serif" color="#FFFFFF">ระดับผู้ใช้</font></td>
<td width="11%" align="center" bgcolor="#A10200"><font size="2" face="MS Sans Serif, Tahoma, sans-serif" color="#FFFFFF">แก้ไข</font></td>
<td width="10%" align="center" bgcolor="#A10200"><font size="2" face="MS Sans Serif, Tahoma, sans-serif" color="#FFFFFF">ลบ</font></td>
</tr>
<?
switch ($data["class"]){
case admin:
$data["class"]="ผู้ดูแลระบบ";
break;
case staff:
$data["class"]="เจ้าหน้าที่พัสดุ";
break;
case ceo:
$data["class"]="ผู้บริหาร";
break;
case user:
$data["class"]="เจ้าหน้าที่ฝ่าย";
break;
}?>
<tr bgcolor="<? if($i%2==0)echo "#FFECFF"; else echo "#FFFFFF";?>">
<td align="left" bgcolor="#F0ECEB"><div align="center"><font face="MS Sans Serif, Tahoma, sans-serif" size="2" color="#990000"> <? echo $i+1+($page-1)*20;?></font></div></td>
<td align="left" bgcolor="#FFFFFF"><div align="left"><font face="MS Sans Serif, Tahoma, sans-serif" size="2" color="#990000"> <? echo $data["name"];?> <? echo $data["lastname"];?></font></div></td>
<td align="left" bgcolor="#FFFFFF"><div align="left"><font face="MS Sans Serif, Tahoma, sans-serif" size="2" color="#990000"> </font><font face="MS Sans Serif, Tahoma, sans-serif" size="2" color="#990000"><? echo $data['class'];?></font></div></td>
<td align="left" bgcolor="#FFFFFF"><div align="center"><a href="#" onClick="popup1('<? echo $data["username"];?>');"><img src="../image/edit.png" alt="แก้ไขข้อมูล" width="20" height="20" border="0" /></a></div></td>
<td align="left" bgcolor="#FFFFFF"><div align="center"><a href="delete_user.php?id=<? echo $data["id"];?>" onClick="return confirm('ต้องการลบ <? echo $data["name"];?> หรือไม่')"><img src="../image/delete.gif" alt="ลบรายการ" width="20" height="20" border="0"></a></div></td>
</tr>
<? }?>
</table></td>
</tr>
</table></td>
</tr>
</table>
<div align="center" class="content2">หน้า <?
if($rowsOfPage%20>0)$p=1; else $p=0;
for($i=1;$i<=$rowsOfPage/20+$p;$i++)echo "<a href=?page=$i&Search=$Search&TxtSearch=$TxtSearch> |$i|</a> ";
?>
</strong></div></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
<tr>
<td></td>
</tr>
</table></td>
</tr>
</table>
<br>
</div>
</form></TD>
</TR>
</TBODY>
</TABLE>
</TD>
</TR><td height="2"></TBODY></TABLE>
<!-- InstanceEndEditable --></td>
</tr>
<tr>
<td height="30" align="center" bgcolor="#A20300"><?php
include ("../include/copyright.php");
echo "<center><font size='2' face='MS Sans Serif' color='#ffffff'>$echo</font></center>" ;
echo "<center><font size='2' face='MS Sans Serif' color='#ffffff'>$echo2</font></center>" ;
?></td>
</tr>
</table>
</body>
<!-- InstanceEnd --></html>
Tag : PHP, MySQL
Date :
2014-02-28 23:38:39
By :
nungna11
View :
763
Reply :
6
มันขึ้น error ตามนี้ค่ะ
Parse error: syntax error, unexpected '[', expecting T_PAAMAYIM_NEKUDOTAYIM in C:\xampp\htdocs\ims\admin\show_user.php on line 94
Date :
2014-03-01 00:56:54
By :
nungna11
<input name="TxtSearch" type="text" id="TxtSearch" value="<? if(isset($ _POST["TxtSearch"])) echo $_POST["TxtSearch"];?>" onClick="javascript:txt.value='';">
Date :
2014-03-01 01:06:01
By :
sakuraei
มันขึ้น error ตามนี้ค่ะ
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\ims\admin\show_user.php on line 71
Date :
2014-03-01 07:53:50
By :
nungna11
ใส่ or die(mysql_error()) ต่อท้ายทุกบรรทัดที่มีการคิวรี่ข้อมูลครับ
$result=mysql_query($sql) or die(mysql_error()) ;
Date :
2014-03-01 08:14:43
By :
sakuraei
ใส่ or die(mysql_error()) แล้วค่ะขึ้นมัน error ว่า
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%ผู้บริหาร%') or (lastname LIKE '%ผู้บริหาร%' at line 1
Date :
2014-03-03 21:03:10
By :
nungna11
Load balance : Server 04