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 > ทำตาม Tutorial แล้วติด Error นิดหนึ่งครับ แต่ไม่รู้ผิดตรงไหน มัน Error แบบนี้หนะครับ



 

ทำตาม Tutorial แล้วติด Error นิดหนึ่งครับ แต่ไม่รู้ผิดตรงไหน มัน Error แบบนี้หนะครับ

 



Topic : 054095



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

สมาชิกที่ใส่เสื้อไทยครีเอท

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



พอดีทำตาม https://www.thaicreate.com/php/php-mysql-search-record-paging.html
แล้วติด Error นิดหนึ่งครับ ปูก็เชคหมดแล้วนะครับ แต่ไม่รู้ผิดตรงไหน มัน Error แบบนี้หนะครับ


SELECT * FROM customer WHERE (Name LIKE '%nottpoo%' or Email LIKE '%nottpoo%')

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 '-2,2' at line 1


Code (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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874" />
<title>Untitled Document</title>
</head>

<body>
	<form action="<? $_SERVER['SCRIPT_NAME'];?>" method="get" name="frmSearch">
    	<table width="300" border="0">
        	<tr>
                <th>Keyword
                <input type="text" name="txtKeyword" id="txtKeyword" value="<?=$_GET["txtKeyword"];?> "/></th>
                <th><input type="submit" value="Search" /></th>
              </tr>
            </table>
    </form>
    <?
		if($_GET["txtKeyword"]!="")
			{
				$conn = mysql_connect("localhost","root","root") or die (mysql_error());
				$objconn=mysql_select_db("connectdb");
				//Search by name or Email
				$sql="SELECT * FROM customer WHERE (Name LIKE '%".$_GET["txtKeyword"]."%' or Email LIKE '%".$_GET["txtKeyword"]."%')";
				echo $sql."<br>" ;
				$query = mysql_query($sql) or die (mysql_error());
				$num_rows = mysql_num_rows($query);
				
				$per_page = 2; // Per Page
				$page = $_GET["Page"];
					if(!$_GET["Page"])
						{
								$page = 1;
						}//if
                         $prev_page = $Page-1;
						$next_page = $Page+1;
						
						$page_start = (($per_page*page)-$per_page);
							if ($num_rows<=$per_page)
							{
								$num_pages = 1;
							}//if
                            else if (($num_rows % $per_page)==0)
							{
								$num_pages = ($num_rows / $per_page);
							}//else if
							else
							{
								$num_pages = ($num_rows / $per_page)+1;
								$num_pages = (int)$num_pages;
							}//else
						$sql.="ORDER  BY  CustomerID  ASC  LIMIT  $page_start,$per_page";
						$query=mysql_query($sql) or die (mysql_error());
						echo "sql : ".$sql;
						?>
                        <table width="800"  border="1" cellspacing="0" cellpadding="0" bordercolor="#333333">
                              <tr bgcolor="#FFFFFF">
                                    <th><div align="center">CustomerID</div></th>
                                    <th><div align="center">Name</div></th>
                                    <th><div align="center">E-mail</div></th>
                                    <th><div align="center">Country Code</div></th>
                                    <th><div align="center">Budget</div></th>
                                    <th><div align="center">Used</div></th>
                               </tr>
                         <?
						 while ($rec=mysql_fetch_assoc($query))
						 {
						 ?>
						 	<tr bgcolor="#FFFFFF">
									<td><div align="center"><?=$rec["CustomerID"];?></div></td>
									<td width="30%"><?=$rec["Name"];?></td>
									<td  width="30%"><?=$rec["Email"];?></td>
									<td  width="20%"><div align="center"><?=$rec["CountryCode"]?></div></td>
									<td width="20%"><div align="right"><?=$rec["Budget"];?></div></td>
									<td width="20%"><div align="right"><?=$rec["Used"];?></div></td>
							</tr>
                           <?
						 }//while
						 ?>
                         </table>
                         <br>
                         Total :  <?=$num_rows;?> Recode : <?=$num_pages?> Page :
                         <?
						 	if ($per_page)
							{
								echo "<a href='$_SERVER[SCRIPT_NAME]?Page=$prev_page&txtKeyword=$_GET[txtKeyword]'><< Back</a>";
							}//if
							
							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
							}//for
							if ($page !=$num_pages)
							{
								echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$next_page&txtKeyword=$_GET[txtKeyword]'>Next>></a> ";
							}//if
                         mysql_close($conn); 
			}//if
	?>
</body>
</html>




Tag : PHP









ประวัติการแก้ไข
2011-01-07 10:28:54
Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2011-01-07 10:27:37 By : nottpoo View : 804 Reply : 2
 

 

No. 1



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



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


ลองปรับดูครับแก้ให้แล้ว
<html>
<head>
<title>ThaiCreate.Com PHP & MySQL Tutorial</title>
</head>
<body>
<form name="frmSearch" method="get" action="<?=$_SERVER['SCRIPT_NAME'];?>">
<table width="599" border="1">
<tr>
<th>Keyword
<input name="txtKeyword" type="text" id="txtKeyword" value="<?=$_GET["txtKeyword"];?>">
<input type="submit" value="Search"></th>
</tr>
</table>
</form>
<?
if($_GET["txtKeyword"] != "")
{
$objConnect = mysql_connect("localhost","root","123456") or die("Error Connect to Database");
$objDB = mysql_select_db("demo");
// Search By Name or Email
$strSQL = "SELECT * FROM tb_customer WHERE (Name LIKE '%".$_GET["txtKeyword"]."%' or Email LIKE '%".$_GET["txtKeyword"]."%')";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$Num_Rows = mysql_num_rows($objQuery);


$Per_Page = 1; // 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">Name </div></th>
<th width="198"> <div align="center">Email </div></th>
<th width="97"> <div align="center">CountryCode </div></th>
<th width="59"> <div align="center">Budget </div></th>
<th width="71"> <div align="center">Used </div></th>
</tr>
<?
while($objResult = mysql_fetch_array($objQuery))
{
?>
<tr>
<td><div align="center"><?=$objResult["CustomerID"];?></div></td>
<td><?=$objResult["Name"];?></td>
<td><?=$objResult["Email"];?></td>
<td><div align="center"><?=$objResult["CountryCode"];?></div></td>
<td align="right"><?=$objResult["Budget"];?></td>
<td align="right"><?=$objResult["Used"];?></td>
</tr>
<?
}
?>
</table>
<br>
Total <?= $Num_Rows;?> Record : <?=$Num_Pages;?> Page :
<?
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>






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-01-07 11:03:43 By : gogo01
 


 

No. 2



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

สมาชิกที่ใส่เสื้อไทยครีเอท

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

$page_start = (($per_page*page)-$per_page); ตรงนี้ปูลืม $ page แก้เป็น $page
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-01-07 11:52:56 By : keedkean.com
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ทำตาม Tutorial แล้วติด Error นิดหนึ่งครับ แต่ไม่รู้ผิดตรงไหน มัน Error แบบนี้หนะครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ 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 00
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 อัตราราคา คลิกที่นี่