สอบถามเกี่ยวกับฟังก์ชัน search ในหน้าเว็บเพจค๊ะ ^_^/
Code (PHP)
<?
$key ='';
if($searchterm != '')
{
$key .= "and pro_name LIKE '$searchterm' ";
}
if($searchterm2 != '')
{
$key .= "and categories = '$searchterm2' ";
}
$sql = "SELECT *
FROM product,sitesettings
WHERE `approved` = 'Yes' $key ";
$query = mysql_query($sql)or die (mysql_error());
?>
ลองนำไปทดสอบดูน่ะครับ
Date :
2012-10-05 09:01:54
By :
fiet
อันนี้เป็นโค๊ดเต็มค๊ะ
Code (PHP)
<?PHP session_start();
/**
*
*
*
*/
include("connect.php");
$page_name = "search.php";
if(isset($_POST['searchterm']) || isset($_POST['searchterm']) || isset($_GET['searchterm'])) //if user pressed search
{
if(isset($_GET['searchterm'])) $searchterm = mysql_real_escape_string($_GET['searchterm']);
function filter($arr) {
return array_map('mysql_real_escape_string', $arr);
}
mysql_query("UPDATE searches SET `searchterm` = '".mysql_real_escape_string($_POST['searchterm'])."' WHERE id='1' ") or die(mysql_error());
if(!mysql_query)
{
echo 'Query failed '.mysql_error();
exit();
}header( 'Location: search' ) ;
}
$searchresult = mysql_query("SELECT searchterm FROM searches");
while($search_row = mysql_fetch_array($searchresult))
{
$title = " ".$lang['SEARCH_RESULTS_FOR']." ".$search_row['searchterm']."";
$searchterm = mysql_real_escape_string($search_row['searchterm']);
}
$rpp = 15; // results per page
$adjacents = 4;
$page = intval($_GET["page"]);
if(!$page) $page = 1;
$reload = "search";
?>
<form id="form2" name="form2" method="post" action="search.php">
<div align="center">
<span class="style40">
<select name="searchterm2" id="txt_search2"onchange="location.href(this.value)">
<option>---------All---------</option>
<option>Electronic</option>
<option>cosmetic</option>
<option>book</option>
</select>
<input name="searchterm" type="text" id="txt_search1"/>
</span>
<label></label>
<input name="Search1" type="submit" id="Search1" value="ค้นหา" />
</div>
</form>
<?PHP
$sql = "SELECT * FROM product,sitesettings WHERE `approved` = 'Yes' AND category LIKE '%$searchterm%' AND `approved` = 'Yes' OR cost LIKE '%$searchterm%' AND `approved` = 'Yes' OR country LIKE '%$searchterm%' AND `approved` = 'Yes' OR description LIKE '%$searchterm%' AND `approved` = 'Yes' OR pro_name LIKE '%$searchterm%' AND `approved` = 'Yes' ";
$result2 = mysql_query($sql)or die(mysql_error());
$tcount = mysql_num_rows($result2);
$tpages = ($tcount) ? ceil($tcount/$rpp) : 1;
$count = 0;
$i = ($page-1)*$rpp;
?>
ช่วยแก้ไขให้หน่อยน๊ะค๊ะ \ ^o^ /
ประวัติการแก้ไข 2012-10-05 10:00:49
Date :
2012-10-05 09:56:40
By :
dferru
Load balance : Server 01