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 > ต้องการ Search 5 ฟิวส์ จะต้อง ใช้ and หรือ or ในการ Search ข้อมูล



 

ต้องการ Search 5 ฟิวส์ จะต้อง ใช้ and หรือ or ในการ Search ข้อมูล

 



Topic : 058309



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



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




นี้เป็นตัวอย่างโค้ดตอนนี้ seach ได้เพียง ตัวเดียว คือ comid ครับผม
ประมาณว่า เลือก seach ตัวได้ตัวหนึ่งผู้ใช้ไม่ต้องระบุหมดก็ได้ ผมก้ไม่เข้าใจเหมือนกันว่าทำพี่เข้าให้ผมเขียนแบบนี้ผมว่าน่าจะ seach ตัวเดียวมันก็ขึ้นมาแล้ว

Code (PHP)
 <?php require_once('./Connections/db_conn.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=utf-8" />
<title>Editprofile </title>
<style type="text/css">
<!--
body,td,th {
	font-family: MS Sans Serif, AngsanaUPC, Arial;
	font-size: 14px;
}
.style4 {color: #3399FF}
-->
</style></head>

<body>
<table width="241" height="0" border="0" cellpadding="0" cellspacing="0">
</table>

</table>
<table width="700" height="104" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="263"> </td> 
    <td width="437" valign="top"><form id="form1" name="form1" method="GET" action="<?=$_SERVER['SCRIPT_NAME'];?>">
      <table width="337" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td width="92" height="27"><div align="center"><span class="style4">COMID</span></div></td>
          <td colspan="3"><label>
            <input type="text" name="txtKeyword1" id="txtKeyword1" />
          </label></td>
        </tr>
        <tr>
          <td height="27"><div align="center"><span class="style4">COMSN</span></div></td>
          <td colspan="3"><label>
            <input type="text" name="txtKeyword2" id="txtKeyword2" />
          </label></td>
        </tr>
        <tr>
          <td height="27"><div align="center"><span class="style4">NAME</span></div></td>
          <td colspan="3"><label>
            <input type="text" name="txtKeyword3" id="txtKeyword3" />
          </label></td>
        </tr>
        <tr>
          <td height="28"><div align="center"><span class="style4">BRAND</span></div></td>
          <td colspan="3"><label>
            <input type="text" name="txtKeyword4" id="txtKeyword4" />
          </label></td>
        </tr>
        <tr>
          <td height="26"><div align="center"><span class="style4">TYPE</span></div></td>
          <td colspan="3"><label>
            <input type="text" name="txtKeyword5" id="txtKeyword5" />
          </label></td>
        </tr>
        <tr>
          <td> </td>
          <td width="41"> </td>
          <td width="63"><label>
            <input type="submit" name="button" id="button" value="Serach" />
          </label></td>
          <td width="141"> </td>
        </tr>
        <tr>
          <td> </td>
          <td colspan="3"> </td>
        </tr>
      </table>
        </form>
        
        
       <?php
if($_GET["txtKeyword1"] != "")
	{
	 mysql_connect($hostname_db_conn,$username_db_conn,$password_db_conn);  
    mysql_select_db($database_db_conn); 
	mysql_query('SET CHARACTER SET utf8');
	// Search By Name
	$strSQL = "SELECT  * FROM profilecomputer  WHERE (comID LIKE '%".$_GET["txtKeyword1"]."%' AND comSN LIKE '%".$_GET["txtKeyword2"]."%' AND ownTn LIKE '%".$_GET["txtKeyword3"]."%' AND Brand LIKE '%".$_GET["txtKeyword4"]."%' AND  TYPE LIKE '%".$_GET["txtKeyword5"]."%'  )  ";
	$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 comID ASC LIMIT $Page_Start , $Per_Page";
	$objQuery  = mysql_query($strSQL);

	?>
	<table width="100%" border="1">
	  <tr bgcolor="#00FFFF">
		<!--<th width="91"> <div align="center">CustomerID </div></th> -->
		<th width="25%"> <div align="center">comid</div></th>
		<th width="25%"> <div align="center">comsn</div></th>
		<th width="25%"> <div align="center">name</div></th>
        <th width="25%"> <div align="center">brand</div></th>
         <th width="25%"> <div align="center">type</div></th>
	
	  </tr>
	<?
	while($objResult = mysql_fetch_array($objQuery))
	{
	?>
	  <tr>
		<td><div align="center"><?=$objResult["comID"];?></div></td>
		<td align="center"><?=$objResult["comSN"];?></td>
		<td align="center"><?=$objResult["ownTN"];?></td>
        	<td align="center"><?=$objResult["Brand"];?></td>
            	<td align="center"><?=$objResult["TYPE"];?></td>
        <td align="center"><a href="ShowHerb.php?Model=<?=$objResult["Model"];?>">ดูรายละเอียด..</a></td>
	  </tr>
	<?
	}
	?>
	</table>
	<br>
	จำนวนทั้งหมด <?= $Num_Rows;?> หน้า หน้าที่ : <?=$Num_Pages;?> หน้า :
	<?
	if($Prev_Page)
	{
		echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page&txtKeyword1=$_GET[txtKeyword1]'><< Back</a> ";
	}

	for($i=1; $i<=$Num_Pages; $i++){
		if($i != $Page)
		{
			echo "[ <a href='$_SERVER[SCRIPT_NAME]?Page=$i&txtKeyword1=$_GET[txtKeyword1]'>$i</a> ]";
		}
		else
		{
			echo "<b> $i </b>";
		}
	}
	if($Page!=$Num_Pages)
	{
		echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page&txtKeyword1=$_GET[txtKeyword1]'>Next>></a> ";
	}
	
	mysql_close( );
 
	}	
	?> 
        
        
        
        
        
        
    </td>
  </tr>
 
</table>
</body>
</html>




Tag : PHP









ประวัติการแก้ไข
2011-04-05 11:03:12
Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2011-04-05 10:55:16 By : thelak View : 711 Reply : 3
 

 

No. 1



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

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

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


ตรงนี้อ่ะ
Code (PHP)
$strSQL = "SELECT  * FROM profilecomputer  WHERE (comID LIKE '%".$_GET["txtKeyword1"]."%' AND comSN LIKE '%".$_GET["txtKeyword2"]."%' AND ownTn LIKE '%".$_GET["txtKeyword3"]."%' AND Brand LIKE '%".$_GET["txtKeyword4"]."%' AND  TYPE LIKE '%".$_GET["txtKeyword5"]."%'  )  ";

ลองเปลี่ยนเป็น Or ดู

$strSQL = "SELECT  * FROM profilecomputer  WHERE (comID LIKE '%".$_GET["txtKeyword1"]."%' OR comSN LIKE '%".$_GET["txtKeyword2"]."%' OR ownTn LIKE '%".$_GET["txtKeyword3"]."%' OR Brand LIKE '%".$_GET["txtKeyword4"]."%' OR TYPE LIKE '%".$_GET["txtKeyword5"]."%'  )  ";







แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-04-05 11:15:15 By : salapao_codeman
 


 

No. 2



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

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

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

Code (PHP)
<?
	$strSQL = "SELECT * FROM table WHERE 1 ";

	if($_POST["txt1"] != "")
	{
		$strSQL .= " AND F1 = '".$_POST["txt1"]."' ";
	}

	if($_POST["txt2"] != "")
	{
		$strSQL .= " AND F2 = '".$_POST["txt2"]."' ";
	}
?>



อันนี้กรณีต้องการข้อมูลที่แคบลงครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-04-05 11:17:16 By : webmaster
 

 

No. 3



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



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


ขอบคุณสังคมแห่งการให้มากๆๆครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-04-05 11:33:01 By : thelak
 

   

ค้นหาข้อมูล


   
 

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