|
|
|
ช่วยดู Code ให้หน่อย มัน Search ไม่ได้ ไม่แน่ใจว่าเป็นที่การ query หรือป่าววว ไม่คล่องเท่าไหร่ ..รบกวนผู้ดูโค๊ดนี้ออก มาช่วยแกะหน่อย... |
|
|
|
|
|
|
|
----------------------------------------------------------------------------------
============================================
file : search.php
=========================================
Code (PHP)
<?
session_start();
require("connect.php");
include("function.php");
include("Paginator.class.php");
if ($_POST["ComboSearch"]){ $Search = $_POST["ComboSearch"]; }
if (!$ComboSearch) { //exit;
}
switch ($ComboSearch) {
case "RESEARCHCODE":
$sql='select * from research where researchcode = "'.$_POST["strsearch"].'"';
break;
case "RESEARCHNAME":
$sql='select * from research where researchname like "%'.$_POST["strsearch"].'%"';
// $sql = 'select * from research';
break;
case "STUDENTID":
$sql='select * from research';
$sql='select * from research where studentid like "%'.$_POST["strsearch"].'%"';
break;
case "RESEARCHER":
$sql='select * from research where researcher like "%'.$_POST["strsearch"].'%"';
break;
case "ADVISOR":
$sql='select * from research where advisor like "%'.$_POST["strsearch"].'%"';
break;
case "RESEARCHTYPE":
$sql='select * from research where researtype like "%'.$_POST["strsearch"].'%"';
break;
case "CAMPUS":
$sql='select * from research where campus like "%'.$_POST["strsearch"].'%"';
break;
case "GRADUATEYEAR":
$sql='select * from research where graduateyear like "%'.$_POST["strsearch"].'%"';
break;
}
function totalRecord($sql){
$sql = str_replace("*", "count(*) as count", $sql);
$result_totalRecord = mysql_query($sql);
if(!empty($result_totalRecord) and mysql_num_rows($result_totalRecord)>0)
{
$totalRecord = mysql_fetch_assoc($result_totalRecord);
return $totalRecord["count"];
}
}
############################# Paging #####################################
$paginator = new Paginator();
$paginator->pageShow = 5;
$perPage = 10;
$totalRecord = totalRecord($sql);
$paginator->calculatePages($totalRecord, $perPage);
$pages = $paginator->getPages();
############################# Paging #####################################
$sql .= " order by researchcode ASC {$pages['limit']}";
$result = mysql_query($sql);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><title>ค้นหาข้อมูล</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="font.css" rel="stylesheet" type="text/css">
<style type="text/css">
ul{
list-style:none;
}
<!--
body {
background-color: #F0F0F0;
}
body,td,th {
font-family: Arial;
font-size: 11px;
color: #333333;
}
-->
</style>
<script type="text/javascript"></script>
<link href="font.css" rel="stylesheet" type="text/css">
</head>
<body leftmargin="0" topmargin="0" marginheight="0" marginwidth="0">
<form action="search.php" method="post">
<table id="Table_01" align="center" border="0" cellpadding="0" cellspacing="0" height="757" width="1016" style='background-color:#FC3434;'>
<tbody>
<tr>
<td colspan="4" height="35"> </td>
</tr>
<tr>
<td rowspan="4" height="710" width="26"> </td>
<td colspan="1" height="134" valign="bottom">
<table border="0" cellpadding="0" cellspacing="0" width="100%"><!---header pic---->
<tr>
<td ><img src="images/banner.jpg" width="100%"></td>
</tr>
</table>
<!---header pic----></td>
<td rowspan="4" align="right" height="710" width="31"> </td>
</tr>
<tr>
<td height="23" width="958" align="right">
<? if($_SESSION["username"] != "") { $user = $_SESSION["username"]; } else { $user = "guest"; } ?>
<span class="text_status"><strong>วันที่ : <?=DateThai(); ?> </strong></span>
<span class="text_status"><strong>เข้าใช้โดย คุณ <?=$user; ?> </span> </td>
</tr>
<tr><!---td : body--->
<td height="486" style='background-color:#FFFFFF;'>
<div style='border:0px solid red; width:100%; height:100%;'>
<? include("menu.php"); ?>
<div class="content" style="border:0px solid yellow; float:left; width:745px; height:350px; padding-top:10px; ">
<div style="text-align:center; width:100%; margin-bottom:20px;">
<? print ComboSearch($Search); ?>
<input name="strsearch" type="text" size="50" value="<?print $_POST['strsearch'];?>">
<input type="submit" value="ค้นหา">
</div>
<?
if(!empty($result) and mysql_num_rows($result)>0)
{
?>
<table border="1" width="730" style='margin:auto; border-collapse:collapse;'>
<tr>
<td style="width:10px; text-align:center;">No.</td>
<td style="width:450px; text-align:center;">ชื่องานวิจัย</td>
<td style="width:150px; text-align:center;">ชื่อผู้วิจัย</td>
<td style="width:100px; text-align:center;">ที่ปรึกษา</td>
</tr>
<?
$num = 1;
while ($data = mysql_fetch_assoc($result))
{
?>
<tr>
<td style="width:10px; text-align:center;">
<?php
print $num;
$num++;
?>
</td>
<td style="width:px; text-align:left; padding-left:2px;">
<a href="detail.php?researchcode=<?print $data["RESEARCHCODE"];?>" />
<?php print $data['RESEARCHNAME']; ?>
</a>
</td>
<td style="width:80px; text-align:left; padding-left:2px;">
<?php print $data['RESEARCHER']; ?>
</td>
<td style="width:50px; text-align:left; padding-left:2px;">
<?php print $data['ADVISOR']; ?>
</td>
</tr>
</a>
<?
}
?>
</table>
<div style="border:0px solid red; text-align:center;">
<div style="width:680px; height:50px; margin:auto;">
<ul>
<li>
<a href="<?php print $pages['previous']['url'];?>">
<? $pages['previous']['num'] ;?>
</a>
</li>
<li>
<div>
<?php
foreach($pages['pages'] as $numPage)
{
if($pages['current']['num'] == $numPage['num'])
{
print "<a href='{$numPage['url']}'><span>{$numPage['num']}</span></a> | ";
}
else
{
print "<a href='{$numPage['url']}'>{$numPage['num']}</a> | ";
}
}
?>
</div>
</li>
<li>
<a href="<?php print $pages['next']['url'];?>">
<? $pages['next']['num'] ;?>
</a>
</li>
</ul>
</div>
</div>
<?
}
//mysql_close($connect);
?>
</div>
</div>
</div>
</td>
</tr><!---td : body--->
<tr>
<td colspan="4" height="20"><div align="right"><strong>Copyright ? 2011 G-MTCT MIS SYSTEM </strong> </div></td>
</tr>
</tbody>
</table></form>
</body></html>
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
[color=red][font=Verdana]( file : function.php )[/font][/color]
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Code (PHP)
<?php
require("connect.php");
function DateThai()
{
$strDate = date("Y-m-d H:i:s");
$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 ";
}
function inStr ($needle, $haystack)
{
$needlechars = strlen($needle); //gets the number of characters in our needle
$i = 0;
for($i=0; $i < strlen($haystack); $i++) //creates a loop for the number of characters in our haystack
{
if(substr($haystack, $i, $needlechars) == $needle) //checks to see if the needle is in this segment of the haystack
{
return TRUE; //if it is return true
}
}
return FALSE; //if not, return false
}
function CheckLogin($user, $password)
{
if ($user != "" and $password != "") {
if (inStr("1=1", $user) == false and inStr("1=1", $password) == false){
// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($user);
$mypassword = stripslashes($password);
$myusername = mysql_real_escape_string($user);
$mypassword = mysql_real_escape_string($password);
$sql="SELECT * FROM user WHERE username = '".$myusername."' and password = '".$mypassword."' and userstatus = 'A'";
$result=mysql_query($sql);
if(!empty($result) and mysql_num_rows($result)>0)
{
$user = mysql_fetch_assoc($result);
$_SESSION["username"] = $user["username"];
$_SESSION["userclass"] = $user["userclass"];
$_SESSION["usergroup"] = $user["usergroup"];
return 1;
}else{
return 0;
}
}
}else{
return 3;
}
}
function ComboYear($check){
$str = "";
$sql = "select * from comboconfig where comboname = 'Cmbyear' order by combocode ";
$result = mysql_query($sql);
$str = "<select id='ComboYear' name='ComboYear'><option value=''>---กรุณาเลือก---</option>";
//$chkYear = $_GET["gYear"];
while ($w=mysql_fetch_array($result)) {
if ($w[combocode] == $check){
$str = $str . "<option value='$w[combovalue]' selected='selected' >$w[combovalue]</option>";
}else{
$str = $str . "<option value='$w[combovalue]' >$w[combovalue]</option>";
}
}
$str = $str . "</select>";
return $str;
}
function ComboSearch($check){
$str = "";
$sql = "select * from comboconfig where comboname = 'cmbsearch'";
$result = mysql_query($sql);
$str = "<select id='ComboSearch' name='ComboSearch'> <option value=''>---กรุณาเลือก---</option>";
while ($w=mysql_fetch_array($result)) {
if ($w[combocode] == $check){
$str = $str . "<option value='$w[combocode]' selected='selected' >$w[combovalue]</option>";
}else{
$str = $str . "<option value='$w[combocode]' >$w[combovalue]</option>";
}
}
$str = $str . "</select>";
return $str;
}
function ComboCampus($check){
$str = "";
$sql = "select * from campus where status = 'A'";
$result = mysql_query($sql);
$str = "<select id='ComboCampus' name='ComboCampus'> <option value=''>-----กรุณาเลือก-----</option>";
while ($w=mysql_fetch_array($result)) {
if ($w[combocode] == $check){
$str = $str . "<option value='$w[ID]' selected='selected' >$w[NAME]</option>";
}else{
$str = $str . "<option value='$w[ID]' >$w[NAME]</option>";
}
}
$str = $str . "</select>";
return $str;
}
function ComboAdvisor($check){
$str = "";
$sql = "select * from professor where status = 'A' order by name asc";
$result = mysql_query($sql);
$str = "<select id='ComboAdvisor' name='ComboAdvisor'> ";
while ($w=mysql_fetch_array($result)) {
if ($w[combocode] == $check){
$str = $str . "<option value='$w[ID]' selected='selected' >$w[NAME]</option>";
}else{
$str = $str . "<option value='$w[ID]' >$w[NAME]</option>";
}
}
$str = $str . "</select>";
return $str;
}
function ComboType($check){
$str = "";
$sql = "select * from comboconfig where comboname = 'cmbtype' order by comboname asc";
$result = mysql_query($sql);
$str = "<select id='ComboType' name='ComboType'> <option value=''>-----กรุณาเลือก-----</option>";
while ($w=mysql_fetch_array($result)) {
if ($w[combocode] == $check){
$str = $str . "<option value='$w[combocode]' selected='selected' >$w[combovalue]</option>";
}else{
$str = $str . "<option value='$w[combocode]' >$w[combovalue]</option>";
}
}
$str = $str . "</select>";
return $str;
}
function ComboStatus($check){
$str = "<select id='ComboStatus' name='ComboStatus'>";
if ($check=="A"){
$str = $str . "<option value=''>กรุณาเลือก</option><option value='A' selected='selected' >Active</option><option value='N'>Non-Active</option></select>";
}
else if ($check=="N"){
$str = $str . "<option value=''>กรุณาเลือก</option><option value='A'>Active</option><option value='N' selected='selected' >Non-Active</option></select>";
}
else {
$str = $str . "<option value='' selected='selected' >กรุณาเลือก</option><option value='A'>Active</option><option value='N'>Non-Active</option></select>";
}
return $str;
}
function ComboUserclass($check){
$str = "<select id='ComboUserclass' name='ComboUserclass'>";
if ($check=="admin"){
$str = $str . "<option value=''>กรุณาเลือก</option><option value='admin' selected='selected' >admin</option><option value='user'>user</option></select>";
}
elseif ($check=="user") {
$str = $str . "<option value=''>กรุณาเลือก</option><option value='admin'>admin</option><option value='user' selected='selected' >user</option></select>";
}
else {
$str = $str . "<option value='' selected='selected' >กรุณาเลือก</option><option value='admin'>admin</option><option value='user'>user</option></select>";
}
return $str;
}
function ComboUsergroup($check){
$str = "<select id='ComboUsergroup' name='ComboUsergroup'>";
if ($check=="staff"){
$str = $str . "<option value=''>กรุณาเลือก</option><option value='staff' selected='selected' >staff</option><option value='teacher'>teacher</option><option value='student'>student</option></select>";
}
else if($check=="teacher") {
$str = $str . "<option value=''>กรุณาเลือก</option><option value='staff'>staff</option><option value='teacher' selected='selected' >teacher</option><option value='student'>student</option></select>";
}
else if($check=="student") {
$str = $str . "<option value=''>กรุณาเลือก</option><option value='staff'>staff</option><option value='teacher'>teacher</option><option value='student' selected='selected' >student</option></select>";
}
else{
$str = $str . "<option value='' selected='selected' >กรุณาเลือก</option><option value='staff'>staff</option><option value='teacher'>teacher</option><option value='student'>student</option></select>";
}
return $str;
}
?>
Tag : PHP, MySQL
|
|
|
|
|
|
Date :
2011-09-27 10:16:07 |
By :
ratsamee_t |
View :
947 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ไม่ลอง print query ที่ได้มา ออกมาดูก่อนหละครับ
|
|
|
|
|
Date :
2011-09-28 03:07:51 |
By :
คนผ่านมา |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|