Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > PHP > PHP Forum > ช่วยด้วยครับ มันขึ้นว่า Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in



 

ช่วยด้วยครับ มันขึ้นว่า Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in

 



Topic : 112254



โพสกระทู้ ( 7 )
บทความ ( 0 )



สถานะออฟไลน์




Code (PHP)
<html>
<head>
<title>search</title>
</head>
<body>
<form name="frmSearch" method="post" action="show.php">
  <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>
</form>
<?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 (name_stu LIKE '%".$_GET["txtKeyword"]."%' or id_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 .=" order  by CustomerID ASC LIMIT $Page_Start , $Per_Page";
	$objQuery  = mysql_query($strSQL);

	?>

	<table width="600" border="1">
	  <tr>
		<th width="91"> <div align="center">CustomerID </div></th>
		<th width="98"> <div align="center">Student ID </div></th>
		<th width="198"> <div align="center">Name</div></th>
		<th width="97"> <div align="center">surname </div></th>
		<th width="59"> <div align="center">Tel. </div></th>
		<th width="71"> <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>
	}
	</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);

		
	?>
</body>
</html>


ข้อมูลที่ในตารางที่ดึงข้อมูลจากdatabase ไม่ขึ้นอ่ะ
แต่จำนวนTotal 4 Record มันขึ้นนะครับ แต่ข้อมูลมันไม่ขึ้นและก็แจ้งว่า
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in
C:\AppServ\www\stu_rmutp\admin\search.php on line 68
ซึ่งผมดูกี่ครั้งก็ถูกแล้ว แล้วลองใส่
if(!$result){ echo mysql_error(); } ไปแล้วหรือว่าผมใส่ถูกที่หรือปล่าวอ่ะครับ ขอคำแนะนำหน่อยนะครับ
กราบขอบพระคุณครับ



Tag : PHP







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2014-10-30 23:47:20 By : namkok View : 854 Reply : 6
 

 

No. 2



โพสกระทู้ ( 2,311 )
บทความ ( 1 )



สถานะออฟไลน์


ลอง echo $strSQL; แล้วความผิดปกติ หรือไม่ก็เอาผลที่ได้ไปรันใน phpMyAdmin ดูครับ






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-10-31 00:01:18 By : arm8957
 


 

No. 3



โพสกระทู้ ( 7 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 2 เขียนโดย : arm8957 เมื่อวันที่ 2014-10-31 00:01:18
รายละเอียดของการตอบ ::
ลองใส่echo $strSQL; แล้วอ่ะครับ
แล้วมันแจ้งมาว่า SELECT * FROM form1 WHERE (name_stu LIKE '%%' or id_stu LIKE '%%')



แล้วผมควรจะแก้ยังไงอ่ะครับ[/quote-no


ประวัติการแก้ไข
2014-10-31 00:27:32
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-10-31 00:21:40 By : namkok
 

 

No. 4



โพสกระทู้ ( 2,311 )
บทความ ( 1 )



สถานะออฟไลน์


ไม่ทราบว่า form นี้เป็น form ที่ส่งข้อมูลมาเพื่อค้นหาหรือเปล่า ถ้าใช่ นั่นก็ผิดละครับ เพราะคุณส่งค่า form ไปแบบ POST แต่ตอนรับ คุณไปรับแบบ GET เลือกเอาอย่างใดอย่างหนึ่งครับ แต่ปกติแล้วในการค้นหาส่วนใหญ่เค้าจะส่งแบบ GET
ดังนั้นก็เปลี่ยนจาก method="post" เป็น method="get"
Code
<form name="frmSearch" method="post" action="show.php"> <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> </form>

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-10-31 08:45:13 By : arm8957
 


 

No. 5



โพสกระทู้ ( 7 )
บทความ ( 0 )



สถานะออฟไลน์


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
 


 

No. 6



โพสกระทู้ ( 2,311 )
บทความ ( 1 )



สถานะออฟไลน์


ก็ลองดูละกันครับ สคริปผมลองรันแล้ว ก็สามารถทำงานได้นะ ึข้นอยู่กับว่าคุณระบุชื่อตาราง ชื่อฟิลด์ถูกต้องหรือไม่?
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
 


 

No. 7



โพสกระทู้ ( 318 )
บทความ ( 1 )



สถานะออฟไลน์
Twitter Facebook

ตรงบันทัดนี้
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
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ช่วยด้วยครับ มันขึ้นว่า Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 03
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่