|
 |
|
ปัญหาการค้นหาฐานข้อมูลใน php ส่งข้อมูลได้แต่แสดงไม่ออก |
|
 |
|
|
 |
 |
|
ถ้าผมใส่ ฟ ในโค้ดฐานข้อมูลนั้น ออกนะครับ แต่ใส่ทางหน้าเว็บtext boxไม่ออก
|
 |
 |
 |
 |
Date :
2011-05-23 02:08:59 |
By :
veeitdata5 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
<?php
$txtsearch=$_REQUEST['txtsearch']; $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 department ";
$strSQL .= "WHERE department_code LIKE '%$txtsearch%' ";
$result = mysql_query($strSQL);
while($rs = mysql_fetch_array($result))
{
?>
ต้องใส่ตัวแปรให้มันครบครับ
|
 |
 |
 |
 |
Date :
2011-05-23 03:15:32 |
By :
deawx |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อ่ะยังไม่ออกครับ ผมลองตามนี้แล้ว เวลาส่ง ผมลองใช้ทั้ง POST และ GET ก็ยังส่งไม่ได้ครับ
|
 |
 |
 |
 |
Date :
2011-05-23 08:51:39 |
By :
veeitdata5 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เอาฟอร์มมาโพสลงด้วยครับ
|
 |
 |
 |
 |
Date :
2011-05-23 09:22:03 |
By :
Dragons_first |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ครับผม
หน้าค้นหาข้อมูล สาขาวิชา
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">
</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>
</table></td>
<td rowspan="3" width="20" height="483" background="images/images/web_04.jpg"> </td>
<td width="925" align="right"></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"><p><br>
<span class="manu">ผลการค้นหาข้อมูลสาขาวิชาคำว่า :
<?php echo $_REQUEST["txtsearch"]; ?></span></p>
<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
$txtsearch=$_REQUEST['txtsearch'];
$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 department ";
$strSQL .= "WHERE department_code LIKE '%$txtsearch%' ";
$result = mysql_query($strSQL);
while($rs = mysql_fetch_array($result))
{
?>
<tr>
<td align="center" class="txt1"><span class="txt2"><?php echo $rs["department_code"]?></span></td>
<td class="txt1"><span class="txt2"><?php echo $rs["department_name"]?></span></td>
<td align="center" class="txt1"><span class="txt2"><?php echo $rs["lecturer_id"]?></span></td>
</tr>
<?php } ?>
</table>
<p><a href="searchform.php" class="link">ค้นหาอีกรอบ</a></p></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);
?>
หน้าแสดงผล หลังจากป้อนข้อมูลมาแล้ว
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">
</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>
</table></td>
<td rowspan="3" width="20" height="483" background="images/images/web_04.jpg"> </td>
<td width="925" align="right"></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"><p><br>
<span class="manu">ผลการค้นหาข้อมูลสาขาวิชาคำว่า :
<?php echo $_REQUEST["txtsearch"]; ?></span></p>
<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
$txtsearch=$_REQUEST['txtsearch'];
$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 department ";
$strSQL .= "WHERE department_code LIKE '%$txtsearch%' ";
$result = mysql_query($strSQL);
while($rs = mysql_fetch_array($result))
{
?>
<tr>
<td align="center" class="txt1"><span class="txt2"><?php echo $rs["department_code"]?></span></td>
<td class="txt1"><span class="txt2"><?php echo $rs["department_name"]?></span></td>
<td align="center" class="txt1"><span class="txt2"><?php echo $rs["lecturer_id"]?></span></td>
</tr>
<?php } ?>
</table>
<p><a href="searchform.php" class="link">ค้นหาอีกรอบ</a></p></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-23 09:32:30 |
By :
veeitdata5 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
รบกวนแก้ไขด้วยนะครับ สงสัยจะลงซ้ำกัน
|
 |
 |
 |
 |
Date :
2011-05-23 09:39:49 |
By :
Dragons_first |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ครับผม อันนี้แก้นะครับ
หน้าค้นหา
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
$("#formsearch").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>
</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"></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"><p><br>
<span class="manu">ค้นหาข้อมูลสาขาวิชา</span><br>
<span class="txt2">ค้นหาได้เฉพาะชื่อสาชาวิชาเท่านั้น</span></p>
<form action="departmentshow.php" method="post" name="formsearch" id="formsearch">
<label for="txtsearch"></label>
<input name="txtsearch" type="text" id="txtsearch" maxlength="20">
<input type="submit" name="butsearch" id="butsearch" value="ค้นหา">
</form>
<p><br>
<br>
</p></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);
?>
หน้าที่สอง แสดงผล หลังจากป้อนข้อมูลแล้ว
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">
</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>
</table></td>
<td rowspan="3" width="20" height="483" background="images/images/web_04.jpg"> </td>
<td width="925" align="right"></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"><p><br>
<span class="manu">ผลการค้นหาข้อมูลสาขาวิชาคำว่า :
<?php echo $_REQUEST["txtsearch"]; ?></span></p>
<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 department ";
$strSQL .= "WHERE department_name LIKE '%txtsearch%' ";
$result = mysql_query($strSQL);
while($rs = mysql_fetch_array($result))
{
?>
<tr>
<td align="center" class="txt1"><span class="txt2"><?php echo $rs["department_code"]?></span></td>
<td class="txt1"><span class="txt2"><?php echo $rs["department_name"]?></span></td>
<td align="center" class="txt1"><span class="txt2"><?php echo $rs["lecturer_id"]?></span></td>
</tr>
<?php } ?>
</table>
<p><a href="searchform.php" class="link">ค้นหาอีกรอบ</a></p></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-23 10:21:36 |
By :
VeeViolet5 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองดูนะครับ
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
$("#formsearch").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>
</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"></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"><p><br>
<span class="manu">ค้นหาข้อมูลสาขาวิชา</span><br>
<span class="txt2">ค้นหาได้เฉพาะชื่อสาชาวิชาเท่านั้น</span></p>
<form action="departmentshow.php" method="GET" name="formsearch" id="formsearch">
<label for="txtsearch"></label>
<input name="txtsearch" type="text" id="txtsearch" maxlength="20">
<input type="submit" name="butsearch" id="butsearch" value="ค้นหา">
</form>
<p><br>
<br>
</p></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);
?>
<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">
</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>
</table></td>
<td rowspan="3" width="20" height="483" background="images/images/web_04.jpg"> </td>
<td width="925" align="right"></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"><p><br>
<span class="manu">ผลการค้นหาข้อมูลสาขาวิชาคำว่า :
<?php echo $_REQUEST["txtsearch"]; ?></span></p>
<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 department ";
$strSQL .= "WHERE department_name LIKE '%".$_GET['txtsearch']."%' ";
$result = mysql_query($strSQL);
while($rs = mysql_fetch_array($result))
{
?>
<tr>
<td align="center" class="txt1"><span class="txt2"><?php echo $rs["department_code"]?></span></td>
<td class="txt1"><span class="txt2"><?php echo $rs["department_name"]?></span></td>
<td align="center" class="txt1"><span class="txt2"><?php echo $rs["lecturer_id"]?></span></td>
</tr>
<?php } ?>
</table>
<p><a href="searchform.php" class="link">ค้นหาอีกรอบ</a></p></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-23 10:49:11 |
By :
Dragons_first |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมได้แล้วแล้วครับ ขอบคุณครับ จะนำไปประยุกต์ใช้
|
 |
 |
 |
 |
Date :
2011-05-24 19:24:10 |
By :
veeitdata5 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 02
|