|
|
|
ช่วยดู code search hแบบ realtime หน่อยครับว่าทำไมถึงใช้งานไม่ได้ เมื่อนำมารวมหน้า ตอนแรก แยกหน้าใช้ได้ครับ |
|
|
|
|
|
|
|
ช่วยดูให้หน่อยครับว่าทำไม ถึง search ไม่ได้ แล้วก็อยากทำให้มัน search แบบ realtime ต้องแก้ตรงไหนบ้างครับ ช่วยหน่อยนะครับ
Code (PHP)
<?
error_reporting(E_ALL ^ E_NOTICE);
session_start();
?>
<?php
include "include/cnmysql.php";
$strSearch = $_POST["mySearch"];
$strPage = $_POST["myPage"];
$strSQL = "SELECT * FROM product WHERE productid LIKE '%".$strSearch."%' or productname LIKE '%".$strSearch."%' ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$Num_Rows = mysql_num_rows($objQuery);
mysql_query("SET NAMES UTF8");
$Per_Page = 30; // Per Page
$Page = $strPage;
if(!$strPage)
{
$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 productid ASC LIMIT $Page_Start , $Per_Page";
$objQuery = mysql_query($strSQL);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>IRBEAUTINA</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="css/style.css" type="text/css" media="all" />
<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="js/jquery.jcarousel.js"></script>
<script type="text/javascript" src="js/cufon-yui.js"></script>
<script type="text/javascript" src="js/MyriadPro.font.js"></script>
<script type="text/javascript" src="js/ArialBold.font.js"></script>
<script type="text/javascript" src="js/jquery-func.js"></script>
<link rel="shortcut icon" type="image/x-icon" href="css/images/iconir.jpg" />
<!--[if IE 6]><link rel="stylesheet" href="css/ie.css" type="text/css" media="all" /><![endif]-->
<script language="JavaScript">
var HttPRequest = false;
function doCallAjax(Search,Page) {
HttPRequest = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
HttPRequest = new XMLHttpRequest();
if (HttPRequest.overrideMimeType) {
HttPRequest.overrideMimeType('text/html');
}
} else if (window.ActiveXObject) { // IE
try {
HttPRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
HttPRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!HttPRequest) {
alert('Cannot create XMLHTTP instance');
return false;
}
var url = 'pricelist2.php';
var pmeters = 'mySearch='+Search;
var pmeters = "mySearch=" + Search +
"&myPage=" + Page;
HttPRequest.open('POST',url,true);
HttPRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
HttPRequest.setRequestHeader("Content-length", pmeters.length);
HttPRequest.setRequestHeader("Connection", "close");
HttPRequest.send(pmeters);
HttPRequest.onreadystatechange = function()
{
if(HttPRequest.readyState == 3) // Loading Request
{
document.getElementById("mySpan").innerHTML = "Now is Loading...";
}
if(HttPRequest.readyState == 4) // Return Request
{
document.getElementById("mySpan").innerHTML = HttPRequest.responseText;
}
}
}
</script>
<body Onload="JavaScript:doCallAjax('','');">
<? include "header2012.php";?>
<form name="frmMain">
<div id="main">
<div class="shell">
<div class="box1">
<? include "leftmenu2012.php";?>
<div id="Bgnew">
<div id="NewCol">
<a href="#"><img class="img1" width="200px" height="140px" src="css/images/1pic1.jpg"/></a>
</div>
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/th_TH/all.js#xfbml=1";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<div class="fb-like-box" data-href="http://www.facebook.com/pages/IR-BEAUTINA/214147611982068" data-width="218" data-height="300" data-show-faces="true" data-stream="false" data-header="true"></div>
</div>
</div>
<div class="box3">
<div class="ContentAb">
<div class="Bannerpai">
<p style="padding:8px 0 0 30px;font-weight:bold;color:#ffffff;text-shadow:1px 0px 1px black">ท่านสามารถเห็น BV / PV ได้เมื่อ ล็อคอินแล้ว ค้นหาสินค้า
<input type="text" name="txtSearch" id="txtSearch"
onkeydown="JavaScript:doCallAjax(document.getElementById('txtSearch').value,'1');"
onkeypress="JavaScript:doCallAjax(document.getElementById('txtSearch').value,'1');"
onkeyup="JavaScript:doCallAjax(document.getElementById('txtSearch').value,'1');"
>
<input type="button" name="btnSearch" id="btnSearch" value="Search"
OnClick="JavaScript:doCallAjax(document.getElementById('txtSearch').value,'1');">
เข้าสู่หน้าสมาชิก </p>
</div>
<br/><br/>
<table class="centerpi" border="1" width="650px">
<tr>
<th>productid</th>
<th>productname</th>
<? if($_SESSION["hcode"]!=""){?>
<th>price</th>
<th>BV</th>
<th>PV</th>
<? }?>
</tr>
<?
$i=0;
while($objResult = mysql_fetch_array($objQuery, MYSQL_ASSOC))
{
$i+=1;
$description=$row["description"];
if($i%2==0){$bgcolor="cacfcd";}
else{$bgcolor="b5b8b7";}
?>
<tr>
<td bgcolor="#<? echo $bgcolor;?>"><?=$objResult["productid"];?></td>
<td bgcolor="#<? echo $bgcolor;?>"><?=$objResult["productname"];?></td>
<? if($_SESSION["hcode"]!=""){?>
<td bgcolor="#<? echo $bgcolor;?>"><?=$objResult["price"];?></td>
<td bgcolor="#<? echo $bgcolor;?>"><?=$objResult["bv"];?></td>
<td bgcolor="#<? echo $bgcolor;?>"><?=$objResult["pv"];?></td>
<? }?>
</tr>
<?
}
?>
</table>
<br/><div class="Navipro">
<p class="Navifont">
<?
if($Prev_Page)
{
echo " <a href=\"JavaScript:doCallAjax(document.getElementById('txtSearch').value,'$Prev_Page')\"><< Back</a> ";
}
for($i=1; $i<=$Num_Pages; $i++){
if($i != $Page)
{
echo " <a href=\"JavaScript:doCallAjax(document.getElementById('txtSearch').value,'$i')\">$i</a> |";
}
else
{
echo "<b> $i </b>";
}
}
if($Page!=$Num_Pages)
{
echo " <a href=\"JavaScript:doCallAjax(document.getElementById('txtSearch').value,'$Next_Page')\">Next >></a> ";
}
mysql_close();
?>
</p>
</div><br/>
<div class="clear1">
</div>
</div>
</div>
</div>
<div class="cl"> </div>
</div>
</div>
<? include "footer2012.php";?></body>
</html>
Tag : PHP, MySQL, Ajax
|
|
|
|
|
|
Date :
2012-03-16 17:46:43 |
By :
onekisz |
View :
971 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เห็นคุณ include jquery มาแล้ว ทำไมไม่ใช้ Ajax ของ jQuery ไปเลยครับ ส่วน Error นั้นไม่รู้จะช่วยยังไงครับ เพราะ debug ด้วยสายตามันยากครับ
|
|
|
|
|
Date :
2012-03-16 20:26:12 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|