ช่วยด้วยครับ มันขึ้นว่า Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in
ลอง echo $strSQL; แล้วความผิดปกติ หรือไม่ก็เอาผลที่ได้ไปรันใน phpMyAdmin ดูครับ
Date :
2014-10-31 00:01:18
By :
arm8957
Code (PHP)
<?php
$objConnect = mysql_connect("localhost","root","gumaibok") or die("Error Connect to Database");
$objDB = mysql_select_db("db_stu_rmutp");
mysql_query("SET NAMES UTF8");
// Search By name_stu or id_stu
$strSQL = "SELECT * FROM form1 WHERE (id_stu LIKE '%".$_GET["txtKeyword"]."%' or name_stu LIKE '%".$_GET["txtKeyword"]."%')";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$Num_Rows = mysql_num_rows($objQuery);
if(!$result){ echo mysql_error(); }
echo $strSQL;
?>
<html>
<head>
<title>search</title>
</head>
<body>
<form name="frmSearch" method="get" action="<?php echo $_SERVER['SCRIPT_NAME'];?>">
<table width="599" border="1">
<tr>
<th>Search
<input name="txtKeyword" type="text" id="txtKeyword" value="<?php echo $_GET["txtKeyword"];?>">
<input type="submit" value="Search"></th>
</tr>
</table>
<?php
$Per_Page = 2; // 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 CustomerID ASC LIMIT $Page_Start , $Per_Page";
$objQuery = mysql_query($strSQL);
?>
<table width="800" border="1">
<tr>
<th width="100"> <div align="center">CustomerID </div></th>
<th width="100"> <div align="center">Student ID </div></th>
<th width="150"> <div align="center">Name</div></th>
<th width="150"> <div align="center">surname </div></th>
<th width="100"> <div align="center">Tel. </div></th>
<th width="200"> <div align="center">Email </div></th>
</tr>
<?php
while( $objResult = mysql_fetch_array( $objQuery))
{
?>
<tr>
<td><div align="center"><?php echo $objResult['id'];?></div></td>
<td><?php echo $objResult['id_stu'];?></td>
<td><?php echo $objResult['name_stu'];?></td>
<td><div align="center"><?php echo $objResult['lastname_stu'];?></div></td>
<td align="right"><?php echo $objResult['mobile_phone_stu'];?></td>
<td align="right"><?php echo $objResult['email_stu'];?></td>
</tr>
<?php
}
?>
</table>
<br>
Total <?php echo $Num_Rows;?> Record : <?php echo $Num_Pages;?> Page :
<?php
if($Prev_Page)
{
echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page&txtKeyword=$_GET[txtKeyword]'><< Back</a> ";
}
for($i=1; $i<=$Num_Pages; $i++){
if($i != $Page)
{
echo "[ <a href='$_SERVER[SCRIPT_NAME]?Page=$i&txtKeyword=$_GET[txtKeyword]'>$i</a> ]";
}
else
{
echo "<b> $i </b>";
}
}
if($Page!=$Num_Pages)
{
echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page&txtKeyword=$_GET[txtKeyword]'>Next>></a> ";
}
mysql_close($objConnect);
?>
</form>
</body>
</html>
ผมลองแก้ไขที่พี่บอกว่ามาแล้วครับ แต่ก็ยังแก้ไม่ได้สักทีอ่ะครับ
Date :
2014-10-31 12:10:22
By :
namkok
ก็ลองดูละกันครับ สคริปผมลองรันแล้ว ก็สามารถทำงานได้นะ ึข้นอยู่กับว่าคุณระบุชื่อตาราง ชื่อฟิลด์ถูกต้องหรือไม่?
Code (PHP)
<?php
$objConnect = mysql_connect("localhost","root","gumaibok") or die("Error Connect to Database");
$objDB = mysql_select_db("db_stu_rmutp")or die("Error can not to select DB");
mysql_query("SET NAMES UTF8");
?>
<html>
<head>
<title>search</title>
</head>
<body>
<form name="frmSearch" method="get" action="<?php echo $_SERVER['SCRIPT_NAME'];?>">
<table width="599" border="1">
<tr>
<th>Search
<input name="txtKeyword" type="text" id="txtKeyword" value="<?php echo $_GET["txtKeyword"];?>">
<input type="submit" value="Search"></th>
</tr>
</table>
<?php
if(!empty($_GET['txtKeyword'])){
// Search By name_stu or id_stu
$strSQL = "SELECT * FROM form1 WHERE (id_stu LIKE '%".$_GET["txtKeyword"]."%') OR (name_stu LIKE '%".$_GET["txtKeyword"]."%') ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$Num_Rows = mysql_num_rows($objQuery);
if(!$result){ echo mysql_error(); }
$Per_Page = 2; // 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 = $strSQL." ORDER BY CustomerID ASC LIMIT $Page_Start , $Per_Page";
$objQuery = mysql_query($strSQL);
?>
<table width="800" border="1">
<tr>
<th width="100"> <div align="center">CustomerID </div></th>
<th width="100"> <div align="center">Student ID </div></th>
<th width="150"> <div align="center">Name</div></th>
<th width="150"> <div align="center">surname </div></th>
<th width="100"> <div align="center">Tel. </div></th>
<th width="200"> <div align="center">Email </div></th>
</tr>
<?php
while( $objResult = mysql_fetch_array( $objQuery))
{
?>
<tr>
<td><div align="center"><?php echo $objResult['id'];?></div></td>
<td><?php echo $objResult['id_stu'];?></td>
<td><?php echo $objResult['name_stu'];?></td>
<td><div align="center"><?php echo $objResult['lastname_stu'];?></div></td>
<td align="right"><?php echo $objResult['mobile_phone_stu'];?></td>
<td align="right"><?php echo $objResult['email_stu'];?></td>
</tr>
<?php
}
?>
</table>
<br>
Total <?php echo $Num_Rows;?> Record : <?php echo $Num_Pages;?> Page :
<?php
if($Prev_Page)
{
echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page&txtKeyword=$_GET[txtKeyword]'><< Back</a> ";
}
for($i=1; $i<=$Num_Pages; $i++){
if($i != $Page)
{
echo "[ <a href='$_SERVER[SCRIPT_NAME]?Page=$i&txtKeyword=$_GET[txtKeyword]'>$i</a> ]";
}
else
{
echo "<b> $i </b>";
}
}
if($Page!=$Num_Pages)
{
echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page&txtKeyword=$_GET[txtKeyword]'>Next>></a> ";
}
mysql_close($objConnect);
}
?>
</form>
</body>
</html>
Date :
2014-10-31 14:42:31
By :
arm8957
ตรงบันทัดนี้
Code (PHP)
$strSQL = $strSQL." ORDER BY CustomerID ASC LIMIT $Page_Start , $Per_Page";
056.
$objQuery = mysql_query($strSQL);
ลองเปลี่ยน CustomerID เป็น id ดูครับ
Code (PHP)
$strSQL = $strSQL." ORDER BY id ASC LIMIT $Page_Start , $Per_Page";
056.
$objQuery = mysql_query($strSQL);
ประวัติการแก้ไข 2014-10-31 15:46:10
Date :
2014-10-31 15:45:29
By :
KKP
Load balance : Server 02