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,028

HOME > PHP > PHP Forum > php สอบถามปัญหา search mysql ข้อมูลที่ตรงกัน 2 เงื่อนไขขึ้นไปค่ะ



 

php สอบถามปัญหา search mysql ข้อมูลที่ตรงกัน 2 เงื่อนไขขึ้นไปค่ะ

 



Topic : 075354



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



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




Code (PHP)
<?php include("head.php"); ?>
<? include_once "connDB.php"; ?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf8" />
<title>::: ผลการค้นหาข้อมูลความร่วมมือ/กิจกรรมนานาชาติ :::</title>
<link href="style/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<center>
<fieldset class="uiforms-fieldset ui-widget-content ui-corner-all"
			style="width: 1120px;"><legend
			class="uiforms-legend ui-widget-header ui-corner-all"> <font
			face="4815_KwangMD_Catthai" size="5" color="#000000"><b>ค้นหาข้อมูลกิจกรรมความร่วมมือกับต่างประเทศ</b></font></legend>

<?  if($submit=="" or $show=="OK"){?>
<form name="form1" method="post" action="search.php?show=OK&strSearch=Y">
<table >
<tr>
<td><font face = "4815_KwangMD_Catthai" size = "4" >ค้นหา :</font><select name="Search2">
<option value="" <? if($Search2==""){ ?>selected<? }?>>------กรุณาเลือกรายการ------</option>
<option value="name" <? if($Search2=='name'){ ?>selected<? }?>>ชื่อ</option>
<option value="activities" <? if($Search2=='activities'){ ?>selected<? }?>>กิจกรรม</option>
<option value="undermou" <? if($Search2=='undermou'){ ?>selected<? }?>>กิจกรรมภายใต้ MOU</option>
</select>
<font face = "4815_KwangMD_Catthai" size = "4" >หน่วยงาน/สำนักวิชา</font><input type="text" name="institute" id="($Search2=='institute')">
<font face = "4815_KwangMD_Catthai" size = "4" >ฝ่าย/สาขาวิชา</font><input type="text" name="school" id="($Search2=='school")'>
<font face = "4815_KwangMD_Catthai" size = "4" >ระหว่างวันที่</font><input type="text" name="startDate" id="startDate" size="10 px">
<font face = "4815_KwangMD_Catthai" size = "4" >ถึงวันที่</font><input type="text" name="endDate" id="endDate" size="10 px">
<input name="Search" type="text" size="14" value="<? echo $Search?>"onFocus="this.value = '';">
<input type="submit" name="submit" value="Search" style="width:50px; ">
</td></tr>



</table>
</form>

<?
if(!isset($start)){
$start = 0;
$page=1;
}
$limit = '10';

if($strSearch=="Y"){
$Qtotal = mysql_query("select * from dbcooperation Where ".$Search2." like '%".$Search."%'  ");

     $a=($Search2=='activities');
	 $b=startDate;
	 $cendDate;
	 $d=($Search2=='shcool');
	 $e=($Search2=='institutel');
		
		
 if($a!="" && $b=="" && $c=="" && $d!=="" && $e!==""){
	      $Qtotal  = 'select * from dbcooperation where durationsince  like "%'.$b.'%" and  durationto like "%'.$c.'%" ';
 }
 elseif ($a="" && $b!=="" && $c!=="" && $d!=="" && $e=="") {
 		  $Qtotal  = 'select * from dbcooperation where institutel like "%'.$e.'%" and activities like "%'.$a.'%" ';
 	
 }elseif ($a="" && $b!=="" && $c!=="" && $d=="" && $e!==""){
 	 $Qtotal  = 'select * from dbcooperation where school like "%'.$d.'%" and activities like "%'.$a.'%" ';
 	
 }

}else{
$Qtotal = mysql_query("select * from dbcooperation");
}

$total = mysql_num_rows($Qtotal); 
if($strSearch=="Y"){
$Query = mysql_query("select * from dbcooperation Where ".$Search2." like '%".$Search."%'   order  by  id DESC LIMIT $start,$limit");
}else {
$Query= mysql_query("select * from dbcooperation order  by  id DESC LIMIT $start,$limit");
}

$totalp = mysql_num_rows($Query);
$xx=$totalp+$start;
$yy=$start+1;
echo "<font face = 4815_KwangMD_Catthai size = 5 >"."ข้อมูลที่ "."</font>".$yy."<font face = 4815_KwangMD_Catthai size = 5 >"." ถึงข้อมูลที่  "."</font> ".$xx;
printf("<font face = 4815_KwangMD_Catthai size = 5 >"." | จากทั้งหมด %d รายการ  "."</font>",$total);
printf("<font face = 4815_KwangMD_Catthai size = 5 >"."  | หน้าที่ %d <br />"."</font>",$page);
?><br>
		<h2><font face = "4815_KwangMD_Catthai" size = "6" color='#000000' > สรุปกิจกรรมความร่วมมือ/กิจกรรมนานาชาติ </font></h2>
	<table border="0" cellpadding="2" cellspacing="2" bgcolor = "#FoFoFo">
	
		<tr bgcolor="#FFA500 ">
			<th  width="180"><font face = "4815_KwangMD_Catthai" size = "5" ><B>หน่วยงาน</B></font></th>
			<th  width="200"><font face = "4815_KwangMD_Catthai" size = "5" ><B>ประเภทกิจกรรม</B></font></th>
			<th  width="200"><font face = "4815_KwangMD_Catthai" size = "5" ><B>ชื่อ-สกุล</B></font></th>
			<th  width="386"><font face = "4815_KwangMD_Catthai" size = "5" ><B>รายละเอียด</B></font></th>
		</tr>
<?
while($arr = mysql_fetch_array($Query)){
$autoid = $arr['id'];
$i++;
if($i%2==0){
$bg = "#CCCCCC";
}else{
$bg = "#FFFFFF";
}
?>
<tr bgcolor="<? echo $bg?>" onmouseover="this.style.backgroundColor='#CCFFCC'" onmouseout="this.style.backgroundColor=''" valign="top">
<td><br><div align='center'><font face = "MS Sans Serif" size = "2"><?=$arr["institute"];?></font></div></td>

<td><br><font face = "MS Sans Serif" size = "2"><?=$arr["activities"];?></font></td>

<td><br><div align='center'><font face = "MS Sans Serif" size = "2"><?=$arr["title"];?></font>
<font face = "MS Sans Serif" size = "2"><?=$arr["name"];?></font></div></td>
 

<td><br><font face = "MS Sans Serif" size = "2"><?=$arr["details"];?></font><br>
<font face = "MS Sans Serif" size = "2"><font  color='navy'>วันที่ดำเนินกิจกรรม :</font><?=DateThai($arr["durationsince"]);?><?=DateThai($arr["durationto"]);?></font><br>
 <font face = "MS Sans Serif" size = "2"><Font color='navy'> แหล่งงบประมาณ : </font><?=$arr["fund"];?></font><br><br>
 </td>
</tr>
<? }?>

</table>

<? }?>
  <div id="footer">
<? if($submit=="" or $show=="OK"){
$page = ceil($total/$limit);
for($i=1;$i<=$page;$i++){
if($_GET['page']==$i){
echo "[<a href='?start=".$limit*($i-1)."&page=$i&strSearch=$strSearch&Search=$Search&Search2=$Search2'><B>$i</B></A>]";
}else{
echo "[<a href='?start=".$limit*($i-1)."&page=$i&strSearch=$strSearch&Search=$Search&Search2=$Search2'>$i</A>]";
}}} ?>
<?php 
 
function DateThai($strDate)
{
$strYear = date("Y",strtotime($strDate))+543;
$strMonth= date("n",strtotime($strDate));
$strDay= date("j",strtotime($strDate));
$strHour= date("H",strtotime($strDate));
$strMinute= date("i",strtotime($strDate));
$strSeconds= date("s",strtotime($strDate));
$strMonthCut = Array("","ม.ค.","ก.พ.","มี.ค.","เม.ย.","พ.ค.","มิ.ย.","ก.ค.","ส.ค.","ก.ย.","ต.ค.","พ.ย.","ธ.ค.");
$strMonthThai=$strMonthCut[$strMonth];
return "$strDay $strMonthThai $strYear";
} 
return $strDate = "2008-08-14 ";

?>
</div> 

</fieldset>
</center>
</body>
</html>
<!-- if($search2=='ค้นหาหน่วยงานและกิจกรรม'){
$sql="slect * from Where institute='คำค้นหา' and activities='คำค้นหา' "
} -->






search



ต้องการค้นหาจาก
- ชื่อ(ทำได้แล้ว)
-กิจกรรม(ทำได้แล้ว)
-กิจกรรมภายใต้ mou(ทำได้แล้ว)
-วันที่(ยังทำไม่ได้)
-กิจกรรมและหน่วยงาน/สำนักวิชา(ยังทำไม่ได้)
-กิจกรรมและฝ่าย/สาขาวิชา(ยังทำไม่ได้)
*** ชื่อ(เงื่อนไขเดียว),กิจกรรม(เงื่อนไขเดียว),กิจกรรมภายใต้ mou(เงื่อนไขเดียว),วันที่(สองเงื่อนไขที่ตรงกัน),กิจกรรมและหน่วยงาน/สำนักวิชา(สองเงื่อนไขที่ตรงกัน),กิจกรรมและฝ่าย/สาขาวิชา(สองเงื่อนไขที่ตรงกัน)

รบกวนพี่ๆช่วยดูให้หน่อยนะค่ะว่าโค้ดผิดตรงไหนมันถึงไมรันไม่ออกค่ะ



Tag : MySQL, HTML/CSS, Ajax, jQuery







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2012-03-11 21:22:48 By : Yarindaaa View : 7553 Reply : 3
 

 

No. 1



โพสกระทู้ ( 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 : 2012-03-12 06:08:52 By : webmaster
 


 

No. 2



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



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


ตอบความคิดเห็นที่ : 1 เขียนโดย : webmaster เมื่อวันที่ 2012-03-12 06:08:52
รายละเอียดของการตอบ ::
ค่ะ ขอบคุณมากๆๆค่ะพี่วิน แต่ว่ายังงอยู่ดีค่ะต้องเอาโค้ดตรงนี้ไปเพิ่มในส่วนไหนค่ะ เอาไปแก้ในส่วนลอจิกทั้งหมดเลยหรอค่ะหรือยังไง เพราะตอนนี้แก้จนตาลายล่ะค่ะ มือใหม่ค่ะรบกวนแนะนำอีกทีนะค่ะ ขอบคุณค่ะ

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-03-12 09:44:36 By : Yarindaaa
 

 

No. 3



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

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

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

ตรง Search ครับ ลองใช้วิธีนี้ในการกำหนดเงื่อนไขของ SQL มันช่วยให้เขียน WHERE ได้ง่ายขึ้น
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-03-13 06:41:37 By : webmaster
 

   

ค้นหาข้อมูล


   
 

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