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 > ค้นหาจาก checkbox หลายๆอันพร้อมกันในฐานข้อมูล คือผมมี check box ประมาณ 16 อัน น่ะครับ คือผมจะตรวจสอบว่าค่าใดถูกเช็คมาแล้วนำไปเป็นเงื่อนไขในการค้นหาน่ะครับ



 

ค้นหาจาก checkbox หลายๆอันพร้อมกันในฐานข้อมูล คือผมมี check box ประมาณ 16 อัน น่ะครับ คือผมจะตรวจสอบว่าค่าใดถูกเช็คมาแล้วนำไปเป็นเงื่อนไขในการค้นหาน่ะครับ

 



Topic : 026699



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



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




คือผมมี check box ประมาณ 16 อัน น่ะครับ คือผมจะตรวจสอบว่าค่าใดถูกเช็คมาแล้วนำไปเป็นเงื่อนไขในการค้นหาน่ะครับ โค๊ดข่างล่างนี้ผมเช็คได้ว่าได้เลือกอะไรมาน่ะครับ
Code (PHP)
<?php
$jod_rod=$_REQUEST[jod_rod];
 	 $furniture=$_REQUEST[furniture];  
	 $tel=$_REQUEST[tel];
	 $air=$_REQUEST[air];
	 $pad_lom=$_REQUEST[pad_lom];
	 $ubc=$_REQUEST[ubc];
	 $internet=$_REQUEST[internet];
	 $swim=$_REQUEST[swim];
	 $police=$_REQUEST[police];
	 $key_card=$_REQUEST[key_card];
	 $tv=$_REQUEST[tv];
	 $yod_ren=$_REQUEST[yod_ren];
	 $sak_pa=$_REQUEST[sak_pa];
	 $vong_jorn_pid=$_REQUEST[vong_jorn_pid];
	 $fitnet=$_REQUEST[fitnet];
	 $minimart=$_REQUEST[minimart];  
 
  if($jod_rod !="")
 				{
				print "<font color=blue>jod_rod </font> &nbsp;";
				
				}
				else
				{
				print  "null &nbsp;";
				}
 if($furniture !="")
 				{
				print "<font color=blue>furniture </font> &nbsp;";
				}
				else
				{
				print  "null &nbsp;";
				}
if($tel !="")
 				{
				print "<font color=blue>tel </font> &nbsp;";
				}
				else
				{
				print  "null &nbsp;";
				}
if($air !="")
 				{
				print "<font color=blue>air </font> &nbsp;";
				}
				else
				{
				print  "null &nbsp;";
				}
if($pad_lom !="")
 				{
				print "<font color=blue>pad_lom </font> &nbsp;";
				}
				else
				{
				print  "null &nbsp;";
				}
if($ubc !="")
 				{
				print "<font color=blue>ubc </font> &nbsp;";
				}
				else
				{
				print  "null &nbsp;";
				}
if($internet !="")
 				{
				print "<font color=blue>internet </font> &nbsp;";
				}
				else
				{
				print  "null &nbsp;";
				}
if($swim !="")
 				{
				print "<font color=blue>swim </font> &nbsp;";
				}
				else
				{
				print  "null &nbsp;";
				}
if($police !="")
 				{
				print "<font color=blue>police </font> &nbsp;";
				}
				else
				{
				print  "null &nbsp;";
				}
if($key_card !="")
 				{
				print "<font color=blue>key_card </font> &nbsp;";
				}
				else
				{
				print  "null &nbsp;";
				}												
if($tv !="")
 				{
				print "<font color=blue>tv </font> &nbsp;";
				}
				else
				{
				print  "null &nbsp;";
				}
if($yod_ren !="")
 				{
				print "<font color=blue>yod_ren </font> &nbsp;";
				}
				else
				{
				print  "null &nbsp;";
				}
if($sak_pa !="")
 				{
				print "<font color=blue>sak_pa </font> &nbsp;";
				}
				else
				{
				print  "null &nbsp;";
				}
if($vong_jorn_pid !="")
 				{
				print "<font color=blue>vong_jorn_pid </font> &nbsp;";
				}
				else
				{
				print  "null &nbsp;";
				}
if($fitnet !="")
 				{
				print "<font color=blue>fitnet </font> &nbsp;";
				}
				else
				{
				print  "null  &nbsp;";
				}
if($minimart!="")
 				{
				print "<font color=blue>minimart</font> &nbsp;";
				}
				else
				{
				print  "null &nbsp;";
				}				
?>


แตว่าผมจะติดเงื่อนไขการค้นหาน่ะครับ....


Code (PHP)
<?php
if ($jod_rod !="") { || $furniture !="" || $tel !="" || $air !="" || $pad_lom !="" || $ubc !="" || $internet !="" || $swim !="" || $police !="" || $key_card !="" || $tv !="" || $yod_ren !="" || $sak_pa !="" || $vong_j||n_pid !="" || $fitnet !="" || $minimart !="")
    $condition=" WHERE (jod_rod LIKE '$jod_rod') and (furniture LIKE '$furniture' or tel LIKE '$tel' or air LIKE '$air' or pad_lom LIKE '$pad_lom' or ubc LIKE '$ubc' or internet LIKE '$internet' or swim LIKE '$swim' or police LIKE '$police' or key_card LIKE '$key_card' or tv LIKE '$tv' or yod_ren LIKE '$yod_ren' or sak_pa LIKE '$sak_pa' or vong_jorn_pid LIKE '$vong_jorn_pid' or fitnet LIKE '$fitnet' or minimart LIKE '$minimart')";
	

}

else
	{
	
	$condition=" WHERE (furniture LIKE '$furniture') or (tel LIKE '$tel') or (air LIKE '$air') or (pad_lom LIKE '$pad_lom') or (ubc LIKE '$ubc') or (internet LIKE '$internet') or (swim LIKE '$swim') or (police LIKE '$police') or (key_card LIKE '$key_card') or (tv LIKE '$tv') or (yod_ren LIKE '$yod_ren') or (sak_pa LIKE '$sak_pa') or (vong_jorn_pid LIKE '$vong_jorn_pid') or (fitnet LIKE '$fitnet') or (minimart LIKE '$minimart')";
	}
$sql = "SELECT * FROM ads". $condition;
?>

******************************----------------------------------***************************************************
ผลลัพธ์ที่ได้ไม่ตรงกับเงื่อนไขที่ถูกเลือกมาครับ ----ผมจะทำยังไงเมื่อรู้ค่าที่เลือกมาแล้วสามารถที่จะ นำไปค้นหาในฐานข้อมูลได้ครับ ช่วยผมด้วยน่ะครับ ยากจิงๆ(สำหรับผม)



Tag : - - - -







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2009-04-27 08:43:59 By : ningning View : 1831 Reply : 1
 

 

No. 1



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



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


มาอีกครับท่าน คือผมได้สร้างตัวแปรไว้ดังนี้ น่ะครับ ถ้าเกิดว่าผมเลือกตัวแรก ด้วยเลยน่ะครับจะไม่มีปัญหาเลยครับแสดงผลได้ แต่ถ้าเกิดว่าผมไม้ได้เลือกตัวแรกด้วย จะทำให้ แสดง โค๊ด ===>SELECT * FROM ads where [font=Verdana]and[/font] air LIKE '1' ; ตัว and มันติดกับ where เลยอ่ะครับ ใครพอจะมีวิธี บ้างครับ ช่วยผมหน่อยครับ ควรจะใช้ and ไว้ตรงส่วนไหน เวลาที่มีการเลือกหลายๆ check box อ่ะคับ
Code (PHP)
<?php
if($jod_rod ==1){$condition1=" jod_rod LIKE '$jod_rod'";}else{$condition1="";}
if($furniture ==1){$condition2=" and furniture LIKE '$furniture'";}else{$condition2="";}
if($tel ==1){$condition3=" and tel LIKE '$tel'";}else{$condition3="";}
if($air ==1){$condition4=" and air LIKE '$air'";}else{$condition4="";}
if($pad_lom ==1){$condition5=" and pad_lom LIKE '$pad_lom'";}else{$condition5="";}
if($ubc ==1){$condition6=" and ubc LIKE '$ubc'";}else{$condition6="";}
if($internet ==1){$condition7=" and internet LIKE '$internet'";}else{$condition7="";}
if($swim ==1){$condition8=" and swim LIKE '$swim'";}else{$condition8="";}
if($swim ==1){$condition8=" and swim LIKE '$swim'";}else{$condition8="";}
if($police ==1){$condition9=" and police LIKE '$police'";}else{$condition9="";}
if($key_card ==1){$condition10=" and key_card LIKE '$key_card'";}else{$condition10="";}
if($tv ==1){$condition11=" and tv LIKE '$tv'";}else{$condition11="";}
if($yod_ren ==1){$condition12=" and yod_ren LIKE '$yod_ren'";}else{$condition12="";}
if($sak_pa ==1){$condition13=" and sak_pa LIKE '$sak_pa'";}else{$condition13="";}
if($vong_jorn_pid ==1){$condition14=" and vong_jorn_pid LIKE '$vong_jorn_pid'";}else{$condition14="";}
if($fitnet ==1){$condition15=" and fitnet LIKE '$fitnet'";}else{$condition15="";}
if($minimart ==1){$condition16=" and minimart LIKE '$minimart'";}else{$condition16="";}

	
$condition="$condition1". "$condition2". "$condition3". "$condition4". "$condition5". "$condition6". "$condition7". "$condition8". "$condition9". "$condition10". "$condition11". "$condition12". "$condition13". "$condition14". "$condition15". "$condition16";
			
									
print $sql = "SELECT * FROM ads where ". $condition;   
?>







Date : 2009-04-27 11:54:21 By : ningning
 

   

ค้นหาข้อมูล


   
 

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