|
 |
|
ทำการตรวจสอบ เมนู และแสดงค่า ผ่านทางphp แล้วทำการเรียกข้อมูลอีกตารางหนึ่ง |
|
 |
|
|
 |
 |
|
น่าจะประมาณนี้
Code (PHP)
$(function(){
$("#butsearch").live("click", function(){
chk_value ();
});
});
function chk_value (){
var txt = $("#txtsearch").val();
var list = $('[name=option]:checked').val();
if(txt.length==0){
alert("ใส่ค่าลงไปคับ");
}
else if(list.length==0){
alert("เมนูต้องเลือกด้วยคับ");
}
else if(txt.length==0 && list.length==0){
alert("ให้ใส่ค่าลงไปและเมนูต้องเลือกด้วย");
}
else{
//$("#fromsearch").submit(); //ไม่น่าจะใช้ได้เนื่องจาก เป็น button
// น่าจะเป็นรูปแบบด้านล่างนี้มากกว่า
$.ajax({
type: "POST",
url: "searchfrom.php",
data: "txtsearch="+txt+"&option="+list,
success: function(data){
alert(data);
}
});
}
}
|
ประวัติการแก้ไข 2011-05-19 11:05:41
 |
 |
 |
 |
Date :
2011-05-18 19:28:16 |
By :
TEST_CODE |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณครับที่ตอบเข้า มามี ปัญหาคือ เลือกเมนุแล้ว ไม่สามารถเช็ดค่าเมนูได้ครับ แล้วเวลาเช็ดค่าว่างนี้ ใช้ใน value="0" ใช้ไหมครับ
|
 |
 |
 |
 |
Date :
2011-05-19 11:05:00 |
By :
veeitdata5 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เอา code form มาดูดีกว่าคับ
|
 |
 |
 |
 |
Date :
2011-05-19 11:06:35 |
By :
TEST_CODE |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
จัดไปครับ หมดทางแล้ว T^T ในนี้หน้า index.html ครับ แล้วจัดด้วยนะคับ&&ค่ะ --'
หน้า index.html ทั้งหมด
Code (PHP)
<html>
<head>
<title>ระบบฐานข้อมูล</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="css/webmain.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="js/jquery-1.6.1.min.js"></script>
<script language="javascript">
$(function(){
$("#butsearch").live("click", function(){
chk_value ();
});
});
function chk_value (){
var txt = $("#txtsearch").val();
var list = $('[name=option]:checked').val();
if(txt.length==0){
alert("กรุณาใส่คำค้นหาด้วย");
}
else if(list.length==0){
alert("กรุณาเลือกเมนูด้วย");
}
else if(txt.length==0 || list.length==0){
alert("กรุณาใส่คำค้นหาและเลือกเมนูด้วย");
}
else{
//$("#fromsearch").submit(); //ไม่น่าจะใช้ได้เนื่องจาก เป็น button
// น่าจะเป็นรูปแบบด้านล่างนี้มากกว่า
$.ajax({
type: "POST",
url: "searchfrom.php",
data: "txtsearch="+txt+"&option="+list,
success: function(data){
alert(data);
}
});
}
}
</script>
</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<!-- Save for Web Slices (web.psd) -->
<table id="Table_01" width="1200" height="700" border="0" cellpadding="0" cellspacing="0">
<tr>
<td colspan="6">
<img src="images/images/web_01.gif" width="1200" height="147" alt=""></td>
</tr>
<tr>
<td rowspan="3" width="20" height="483" background="images/images/web_02.jpg"> </td>
<td width="216" rowspan="3" valign="top"><table width="199" border="0" align="center">
<tr>
<td width="200"><img src="images/index.gif" width="16" height="16"><a href="index.html" class="link"> หน้าหลัก</a></td>
</tr>
<tr>
<td height="24"><img src="images/data.gif" width="16" height="16"><a href="research_main.php" class="link"> ข้อมูลงานวิจัย</a><a href="resmain.php" class="link"></a></td>
</tr>
<tr>
<td><img src="images/data.gif" width="16" height="16"><a href="lecturer.php" class="link"> ข้อมูลบุคลากร</a></td>
</tr>
<tr>
<td><img src="images/data.gif" width="16" height="16"><a href="department.php" class="link"> ข้อมูลสาขาวิชา</a></td>
</tr>
</table></td>
<td rowspan="3" width="20" height="483" background="images/images/web_04.jpg"> </td>
<td width="925" align="right"><form action="searchfrom.php" method="post" name="fromsearch" id="fromsearch">
<img src="images/search.gif" width="20" height="20">
<input name="txtsearch" type="text" id="txtsearch" maxlength="20">
<select name="selectfrom" id="selectfrom">
<option value="0">กรุณาเลือก</option>
<option value="1">ข้อมูลงานวิจัย</option>
<option value="2">ข้อมูลบุคลากร</option>
<option value="3">ข้อมูลสาขาวิชา</option>
</select>
<input type="button" name="butsearch" id="butsearch" value="ค้นหา">
</form></td>
<td>
<img src="images/images/web_06.gif" width="1" height="32" alt=""></td>
<td rowspan="3" width="20" height="483" background="images/images/web_07.jpg"> </td>
</tr>
<tr>
<td colspan="2" width="926" height="20" background="images/images/web_08.jpg"> </td>
</tr>
<tr>
<td width="925"><center>
<p><img src="images/pr06.jpg" width="500" height="354" align="top"></p>
</center></td>
<td>
<img src="images/images/web_10.gif" width="1" height="432" alt=""></td>
</tr>
<tr>
<td colspan="6">
<img src="images/images/web_11.gif" width="1200" height="70" alt=""></td>
</tr>
</table>
<!-- End Save for Web Slices -->
</body>
</html>
หน้า searchfrom.php
Code (PHP)
<html>
<head>
<title>ระบบฐานข้อมูล</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="css/webmain.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="js/jquery-1.6.1.min.js"></script>
<script language="javascript">
$(function(){
$("#butsearch").click(function(){
if(($("#txtsearch").val()==""))
alert("กรองข้อมูลไม่ครบ");
else
$("#formdepadd").submit();
});
});
</script>
</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<!-- Save for Web Slices (web.psd) -->
<table id="Table_01" width="1200" height="700" border="0" cellpadding="0" cellspacing="0">
<tr>
<td colspan="6">
<img src="images/images/web_01.gif" width="1200" height="147" alt=""></td>
</tr>
<tr>
<td rowspan="3" width="20" height="483" background="images/images/web_02.jpg"> </td>
<td width="216" rowspan="3" valign="top"><table width="199" border="0" align="center">
<tr>
<td><img src="images/index.gif" width="16" height="16"><a href="index.html" class="link"> หน้าหลัก</a></td>
</tr>
<tr>
<td height="24"><img src="images/data.gif" width="16" height="16"><a href="research_main.php" class="link"> ข้อมูลงานวิจัย</a></td>
</tr>
<tr>
<td><img src="images/data.gif" width="16" height="16"><a href="lecturer.php" class="link"> ข้อมูลบุคลากร</a></td>
</tr>
<tr>
<td><img src="images/data.gif" width="16" height="16"><a href="department.php" class="link"> ข้อมูลสาขาวิชา</a></td>
</tr>
</table>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p></td>
<td rowspan="3" width="20" height="483" background="images/images/web_04.jpg"> </td>
<td width="925" align="right"><form name="form1" method="post" action="searchfrom.php">
<img src="images/search.gif" width="20" height="20">
<input name="txtsearch" type="text" id="txtsearch" maxlength="20">
<select name="selectfrom" id="selectfrom">
<option value="0">กรุณาเลือก</option>
<option value="1">ข้อมูลงานวิจัย</option>
<option value="2">ข้อมูลบุคลากร</option>
<option value="3">ข้อมูลสาขาวิชา</option>
</select>
<input type="button" name="butsearch" id="butsearch" value="ค้นหา">
</form></td>
<td>
<img src="images/images/web_06.gif" width="1" height="32" alt=""></td>
<td rowspan="3" width="20" height="483" background="images/images/web_07.jpg"> </td>
</tr>
<tr>
<td colspan="2" width="926" height="20" background="images/images/web_08.jpg"> </td>
</tr>
<tr>
<td width="925" align="center" valign="top"><br>
<span class="manu">ระบบค้นหา</span><br>
<br>
<table width="442" border="1">
<tr class="txt1" bgcolor="#00CCCC">
<th width="140" scope="col"> </th>
<th width="140" scope="col"> </th>
<th width="140" scope="col"> </th>
</tr>
<?php
$ServerName="localhost";
$UserName="root";
$UserPassword="";
$DataBaseName="research_db";
$conn=mysql_connect($ServerName,$UserName,$UserPassword);
if(!$conn)
die("ไม่สามารถติดต่อกับ MySQL ได้");
mysql_select_db($DataBaseName,$conn)
or die("ไม่สามารถเลือกใช้งานฐานข้อมูล $DataBaseName ได้");
mysql_query("SET NAMES UTF8",$conn);
$strSQL = "SELECT * FROM ";
$strSQL .= "ORDER BY ";
$result=mysql_query($strSQL);
while($rs=mysql_fetch_array($result))
{
?>
<tr>
<td align="center" class="txt1"> </td>
<td class="txt1"> </td>
<td align="center" class="txt1"> </td>
</tr>
<?php } ?>
</table></td>
<td >
<img src="images/images/web_10.gif" width="1" height="432" alt=""></td>
</tr>
<tr>
<td colspan="6">
<img src="images/images/web_11.gif" width="1200" height="70" alt=""></td>
</tr>
</table>
<!-- End Save for Web Slices -->
</body>
</html>
<?php
mysql_close($conn);
?>
|
 |
 |
 |
 |
Date :
2011-05-19 11:15:48 |
By :
veeitdata5 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
1 แยก jquery ไปเขียนอีกไฟล์ แล้วเรียกเอา
2 ลองแก้ฟิวที่ comment ไว้ให้ถูกต้อง
3. เขียนแยกไฟล์ connect database แล้ว include เรียกเอา
Code (PHP)
<html>
<head>
<title>ระบบฐานข้อมูล</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="css/webmain.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="js/jquery-1.6.1.min.js"></script>
<script type="text/javascript" src="js/get_value.js"></script>
</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<!-- Save for Web Slices (web.psd) -->
<table id="Table_01" width="1200" height="700" border="0" cellpadding="0" cellspacing="0">
<tr>
<td colspan="6">
<img src="images/images/web_01.gif" width="1200" height="147" alt=""></td>
</tr>
<tr>
<td rowspan="3" width="20" height="483" background="images/images/web_02.jpg"> </td>
<td width="216" rowspan="3" valign="top"><table width="199" border="0" align="center">
<tr>
<td width="200"><img src="images/index.gif" width="16" height="16"><a href="index.html" class="link"> หน้าหลัก</a></td>
</tr>
<tr>
<td height="24"><img src="images/data.gif" width="16" height="16"><a href="research_main.php" class="link"> ข้อมูลงานวิจัย</a><a href="resmain.php" class="link"></a></td>
</tr>
<tr>
<td><img src="images/data.gif" width="16" height="16"><a href="lecturer.php" class="link"> ข้อมูลบุคลากร</a></td>
</tr>
<tr>
<td><img src="images/data.gif" width="16" height="16"><a href="department.php" class="link"> ข้อมูลสาขาวิชา</a></td>
</tr>
</table></td>
<td rowspan="3" width="20" height="483" background="images/images/web_04.jpg"> </td>
<td width="925" align="right">
<img src="images/search.gif" width="20" height="20">
<input name="txtsearch" type="text" id="txtsearch" maxlength="20">
<select name="selectfrom" id="selectfrom">
<option>กรุณาเลือก</option>
<option value="1">ข้อมูลงานวิจัย</option>
<option value="2">ข้อมูลบุคลากร</option>
<option value="3">ข้อมูลสาขาวิชา</option>
</select>
<input type="button" name="butsearch" id="butsearch" value="ค้นหา">
</td>
<td>
<img src="images/images/web_06.gif" width="1" height="32" alt=""></td>
<td rowspan="3" width="20" height="483" background="images/images/web_07.jpg"> </td>
</tr>
<tr>
<td colspan="2" width="926" height="20" background="images/images/web_08.jpg"> </td>
</tr>
<tr>
<td width="925"><center>
<p> </p>
</center></td>
<td>
<img src="images/images/web_10.gif" width="1" height="432" alt=""></td>
</tr>
<tr>
<td colspan="6">
<img src="images/images/web_11.gif" width="1200" height="70" alt=""></td>
</tr>
</table>
<!-- End Save for Web Slices -->
</body>
</html>
Code (JavaScript)
$(function(){
$("#butsearch").live("click", function(){
chk_value ();
});
});
function chk_value (){
var txt = $("#txtsearch").val();
var list = $('[name=selectfrom]:checked').val();
if(txt.length==0){
alert("กรุณาใส่คำค้นหาด้วย");
}
else if(list.length==0){
alert("กรุณาเลือกเมนูด้วย");
}
else if(txt.length==0 && list.length==0){
alert("กรุณาใส่คำค้นหาและเลือกเมนูด้วย");
}
else{
//$("#fromsearch").submit(); //ไม่น่าจะใช้ได้เนื่องจาก เป็น button
// น่าจะเป็นรูปแบบด้านล่างนี้มากกว่า
$.ajax({
type: "POST",
url: "searchfrom.php",
data: "txtsearch="+txt+"&selectfrom="+list,
success: function(data){
alert(data);
}
});
}
}
Code (PHP)
<? @include ("config.inc.php");
$txtsearch = $_REQUEST['txtsearch'];
$selectfrom = $_REQUEST['selectfrom'];
?>
<table width="442" border="1">
<tr class="txt1" bgcolor="#00CCCC">
<th width="140" scope="col">ลำดับ</th>
<th width="140" scope="col">คำค้น</th>
<th width="140" scope="col">ประเภท</th>
</tr>
<?php
if($txtsearch!=''){
$where = " WHERE ฟิวtxtsearch LIKE '%".$txtsearch."%' "; // แก้ให้ตรง
}
else if($selectfrom!=''){
$where = " WHERE ฟิวselectfrom = '$selectfrom' "; // แก้ให้ตรง
}
else if($txtsearch!='' && $selectfrom!=''){
$where = " WHERE ฟิวtxtsearch LIKE '%".$txtsearch."%' AND ฟิวselectfrom = '$selectfrom' "; // แก้ให้ตรง
}
$strSQL = "SELECT * FROM ชื่อตาราง $where ";
$result=mysql_query($strSQL);
while($rs=mysql_fetch_array($result))
{
?>
<tr>
<td align="center" class="txt1"><?=$rs['id']?></td>
<td class="txt1"><?=$rs['ฟิวtxtsearch']?></td>
<td align="center" class="txt1"><?=$rs['ฟิวselectfrom']?></td>
</tr>
<? }?>
</table>
|
 |
 |
 |
 |
Date :
2011-05-19 11:46:45 |
By :
TEST_CODE |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ด้านล่างสุดนี้ผมต้องสร้าง config.inc.php หรอครับ
|
 |
 |
 |
 |
Date :
2011-05-20 16:43:00 |
By :
veeitdata5 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|