|
 |
|
ขอความช่วยเหลือเรื่องการ search ในหลาย ๆ field ครับ |
|
 |
|
|
 |
 |
|
ผมเขียนคำสั่งค้นหาโดยใช้ Dreamweaver cs5.5
ปัญหาคือ search ได้แค่ field เดียวครับ
ทำยังไงถึงจะ search ได้หลาย field ครับ
-แล้วจะแทรกคำสั่งที่ตรงไหนครับ-
ขอบคุณมาก ๆ เลยครับ
Code (PHP)
<?php require('Connections/book.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$maxRows_search = 10;
$pageNum_search = 0;
if (isset($_GET['pageNum_search'])) {
$pageNum_search = $_GET['pageNum_search'];
}
$startRow_search = $pageNum_search * $maxRows_search;
$colname_search = "-1";
if (isset($_POST['key'])) {
$colname_search = $_POST['key'];
}
mysql_select_db($database_book, $book);
$query_search = sprintf("SELECT * FROM book_data WHERE book_name_en LIKE %s ORDER BY book_name_en ASC", GetSQLValueString("%" . $colname_search . "%", "text"));
$query_limit_search = sprintf("%s LIMIT %d, %d", $query_search, $startRow_search, $maxRows_search);
$search = mysql_query($query_limit_search, $book) or die(mysql_error());
$row_search = mysql_fetch_assoc($search);
if (isset($_GET['totalRows_search'])) {
$totalRows_search = $_GET['totalRows_search'];
} else {
$all_search = mysql_query($query_search);
$totalRows_search = mysql_num_rows($all_search);
}
$totalPages_search = ceil($totalRows_search/$maxRows_search)-1;
?>
<table width="200" border="0.5">
<tr>
<td>ID</td>
<td>EN</td>
<td>TH</td>
<td>Country</td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $row_search['book_id']; ?></td>
<td><?php echo $row_search['book_name_en']; ?></td>
<td><?php echo $row_search['book_name_th']; ?></td>
<td><?php echo $row_search['country']; ?></td>
</tr>
<?php } while ($row_search = mysql_fetch_assoc($search)); ?>
</table>
<?php
mysql_free_result($search);
?>
Tag : PHP, MySQL

|
|
 |
 |
 |
 |
Date :
2012-04-13 07:04:06 |
By :
โต |
View :
1219 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณมาก ๆ ตอบเร็วมากเลยครับ ขอให้มีความสุขวันสงกรานต์ครับ
|
 |
 |
 |
 |
Date :
2012-04-14 17:09:03 |
By :
โต |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|