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 > สอบถามเรื่องการค้นหาแบบ list menu แบบมีคำค้นหน่อยครับ อยากให้มีเงื่อไงครับ [มีรูปครับ]



 

สอบถามเรื่องการค้นหาแบบ list menu แบบมีคำค้นหน่อยครับ อยากให้มีเงื่อไงครับ [มีรูปครับ]

 



Topic : 099660

Guest




สอบถามเรื่องการค้นหาแบบ Dropdown list หน่อยครับ แบบให้ใส่คำค้นหาตามที่เราเลือก list ไว้ จากที่ผมทำ มันสามารถค้นหาได้หมด แต่ ผมอยากให้มันมีเงื่อนไขหน่ะครับ เช่นถ้าเลือก option เป็น ipaddress ใส่คำค้น ว่า Computernameserverlekjaeng จะไม่ออก แต่ถ้าเลือกค่า option เดียวกันค้นหาคำเดียวกันก็จะเจอครับ ช่วยทีคร๊าบบ ขอบคุณมากๆครับ

Search

Code (PHP)
<form name="frmSearch" method="get" action="<?=$_SERVER['SCRIPT_NAME']; ?>">
  <table width="599" border="1" align="center">
    <tr>
      <th>Search 
        <select name="ipaddress" id="ipaddress">
<option>- เลือกรายการ -</option>
<option value="ipaddress" <?if($_POST["ipaddress"]=="ipaddress"){echo"selected";}?>>ipaddress</option>
<option value="namecom" <?if($_POST["namecom"]=="namecom"){echo"selected";}?>>ชื่อเครื่องคอมพิวเตอร์</option>
<option value="party" <?if($_POST["party"]=="party"){echo"selected";}?>>ฝ่าย</option>
<option value="local" <?if($_POST["local"]=="local"){echo"selected";}?>>ที่ตั้ง</option>
</select>

Keyword<input name="txtKeyword" type="text" id="txtKeyword" value="<?=$_POST["txtKeyword"];?>">
      <input type="submit" value="Search"></th>
    </tr>
  </table>
</form>




<p align="center"><a href="phpMySQLAddForm.php" target="_blank">เพิ่มข้อมูล</a>
<?

$objConnect = mysql_connect("localhost","root","11223344") or die("Error Connect to Database");
$objDB = mysql_select_db("mydatabase");
mysql_query("SET NAMES UTF8");
$strSQL = "SELECT * FROM computeripname";

$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
	
	// Search By Name or Email
	
	
	
	
$strSQL = "SELECT * FROM computeripname WHERE(


ipaddress LIKE '%".$_GET["txtKeyword"]."%' or 
namecom LIKE '%".$_GET["txtKeyword"]."%' or 
party LIKE '%".$_GET["txtKeyword"]."%' or 
brand LIKE '%".$_GET["txtKeyword"]."%' or 
local LIKE '%".$_GET["txtKeyword"]."%' or 
note LIKE '%".$_GET["txtKeyword"]."%' 

)";



	$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
	$Num_Rows = mysql_num_rows($objQuery);


	$Per_Page = 10;   // 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 ipaddress	 ASC LIMIT $Page_Start , $Per_Page";
	$objQuery  = mysql_query($strSQL);

	?>




Tag : PHP, MySQL







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2013-08-27 12:51:45 By : lekjaengs View : 1758 Reply : 3
 

 

No. 1



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

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

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

เอาง่ายๆครับตรง value ของ select option เก็บเป็นชื่อ field ใน database ส่วน txtKeyword ก็ตามปกติ แล้วเขียน Query ตามข้างล่าง

Code (PHP)
<select name="opt" id="opt">
<option>- เลือกรายการ -</option>
<option value="ipaddress" <?if($_POST["ipaddress"]=="ipaddress"){echo"selected";}?>>ipaddress</option>
<option value="namecom" <?if($_POST["namecom"]=="namecom"){echo"selected";}?>>ชื่อเครื่องคอมพิวเตอร์</option>
<option value="party" <?if($_POST["party"]=="party"){echo"selected";}?>>ฝ่าย</option>
<option value="local" <?if($_POST["local"]=="local"){echo"selected";}?>>ที่ตั้ง</option>
<option value="note" <?if($_POST["note"]=="note"){echo"selected";}?>>note</option>
</select>

if(!empty($_GET['opt'])){

$field = $_GET['opt']; //ตรงนี้จะได้ว่า จะ where ด้วย field อะไร
$keyword = $_GET['txtKeyword'];
$strSQL = "select * from computeripname  where $field like '%$keyword %'";

}







แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-08-27 13:20:06 By : Manussawin
 


 

No. 2

Guest


ตอบความคิดเห็นที่ : 1 เขียนโดย : Manussawin เมื่อวันที่ 2013-08-27 13:20:06
รายละเอียดของการตอบ ::

ผมลองใส่เเล้วมันขึ้นเเบบนี้น่ะคับ Error Query [select * from computeripname where like '%10.0.255.18 %'] ผมใส่อะไรผิดไปหรือป่าวหรอครับ ตอนนี้ผมตั้ง value ของ select option เก็บเป็นชื่อ field เเล้วครับ มีทั้งหมด 3 อันคือ ipaddress namecom party หน่ะครับ ผมต้องแก้ไขหรือเพิ่มตรงไหนหรอครับ ขอบคุณคับ

Code
<html>
<head>
<title>PHP MySQL Search Record Paging/Pagination</title>
<meta http-equiv=Content-Type content="text/html; charset=UTF-8">
</head>
<body>
<p align="center">ระบบค้นหาชื่อเครื่องคอมพิวเตอร์ (Computer Name)</p>

<form name="frmSearch" method="get" action="<?=$_SERVER['SCRIPT_NAME'];?>">
<table width="599" border="1" align="center">
<tr>
<th>Search
<select name="ddlSelect" id="ddlSelect">
<option>- Select -</option>
<option value="ipaddress" <?if($_POST["ddlSelect"]=="ipaddress"){echo"selected";}?>>ipaddress</option>
<option value="namecom" <?if($_POST["ddlSelect"]=="namecom"){echo"selected";}?>>namecom</option>
<option value="party" <?if($_POST["ddlSelect"]=="party"){echo"selected";}?>>party</option>
</select>
Keyword
<<input name="txtKeyword" type="text" id="txtKeyword" value="<?=$_POST["txtKeyword"];?>">
<input type="submit" value="Search"></th>
</tr>
</table>
</form>




<p align="center"><a href="phpMySQLAddForm.php" target="_blank">เพิ่มข้อมูล</a>
<?

$objConnect = mysql_connect("localhost","root","11223344") or die("Error Connect to Database");
$objDB = mysql_select_db("mydatabase");

mysql_query("SET NAMES UTF8");

// Search By Name or Email

$strSQL = "SELECT * FROM computeripname WHERE 1";
if(!empty($_GET['ddlSelect'])){

$field = $_GET['ipaddress']; //ตรงนี้จะได้ว่า จะ where ด้วย field อะไร

$keyword = $_GET['txtKeyword'];
$strSQL = "select * from computeripname where $field like '%$keyword %'";
}


$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$Num_Rows = mysql_num_rows($objQuery);


$Per_Page = 10; // 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 ipaddress ASC LIMIT $Page_Start , $Per_Page";
$objQuery = mysql_query($strSQL);

?>
</p>
</p>
<table width="1024" border="1" align="center">
<tr bgcolor="#33FF33">
<th width="92"> <div align="center">แก้ไข | ลบ</div></th>
<th width="157"> <div align="center">IP Address </div></th>
<th width="261"> <div align="center">ชื่อเครื่องคอมพิวเตอร์</div></th>
<th width="33"> <div align="center">ฝ่าย</div></th>
<th width="112"> <div align="center">ยี่ห้อ</div></th>
<th width="242"> <div align="center">ที่ตั้ง</div></th>
<th width="81"> <div align="center">หมายเหตุ</div></th>
</tr>
<?
while($objResult = mysql_fetch_array($objQuery))
{
?>
<tr>
<td align="center"><a href="phpMySQLEditRecordForm.php?ipaddress=<?=$objResult["ipaddress"];?>">Edit</a> | <a href="JavaScript:if(confirm('Confirm Delete?')==true){window.location='phpMySQLDeleteRecord.php?ipaddress=<?=$objResult["ipaddress"];?>';}">Delete</a></td>
<td><div align="center"><?=$objResult["ipaddress"];?></div></td>
<td align="center" bgcolor="#CCCCCC"><?=$objResult["namecom"];?></td>
<td align="center"><?=$objResult["party"];?></td>
<td align="center"><?=$objResult["brand"];?></td>
<td align="center"><?=$objResult["local"];?></td>
<td align="center"><?=$objResult["note"];?></td>
</tr>
<?
}
?>
</table>
<br>
<p align="center">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 : 2013-08-29 21:11:50 By : lekjaengs
 

 

No. 3



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

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

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

มี space ก่อน % ท้าย อันนี้ใช่ปัญหาป่าว
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-08-29 21:15:34 By : pjgunner.com
 

   

ค้นหาข้อมูล


   
 

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