คิวรี่รูปภาพออกมาไม่ได้ ค้นหาข้อมูลสมาชิก , หมวดสินค้า , ชื่อสินค้า , รายละเอียดสินค้า , ตัวแทนจำหน่าย ...
Code (PHP)
[php]<?php
require_once '../common/config.php';
$page_start=0;
$per_page=20;
$page = @$_REQUEST['page'];
if(isset($_REQUEST['text_search']) && trim($_REQUEST['text_search'])!= ""){
$txt_search = $_REQUEST['text_search'];
$search_type = $_REQUEST['search_type'];
switch ($search_type){
case 2: $where = "product.product_id LIKE '%" . $txt_search . "%'"; break;
case 3: $where = "product.pro_name LIKE '%" . $txt_search . "%'"; break;
case 4: $where = "category.category_name LIKE '%" . $txt_search . "%'"; break;
}
$sql_data_all = "SELECT count(*) FROM product INNER JOIN category ON product.category_id = category.category_id WHERE " .$where. " ORDER BY product.category_id = category.category_id ASC ";
$qr = mysql_db_query($dbname, $sql_data_all);
$num_rows = mysql_result($qr,0);
if ( empty($page) )
$page = 1;
$prev_page = $page - 1;
$next_page = $page + 1;
$page_start = ( $per_page * $page) - $per_page;
if ( $num_rows <= $per_page )
$num_pages = 1;
else if ( ( $num_rows % $per_page ) == 0 )
$num_pages = ( $num_rows / $per_page );
$num_pages = ( $num_rows / $per_page ) + 1;
$num_pages = ( int ) $num_pages;
$sql_data = "SELECT product.product_id ,
product.pro_name ,
product.pro_price ,
product.pro_description ,
product.idtrade ,
product.product_img,
category.category_name
FROM product INNER JOIN category ON product.category_id = category.category_id
WHERE " .$where. " ORDER BY product.category_id = category.category_id ASC LIMIT $page_start, $per_page";
$data_result = mysql_db_query($dbname,$sql_data);
$count = mysql_num_rows($data_result);
echo mysql_error();
}else{
$sql_data_all = "SELECT count(*) FROM product ";
$qr = mysql_db_query($dbname, $sql_data_all);
echo mysql_error();
$num_rows = mysql_result($qr,0);
if ( empty($page) )
$page = 1;
$prev_page = $page - 1;
$next_page = $page + 1;
$page_start = ( $per_page * $page) - $per_page;
if ( $num_rows <= $per_page )
$num_pages = 1;
else if ( ( $num_rows % $per_page ) == 0 )
$num_pages = ( $num_rows / $per_page );
else
$num_pages = ( $num_rows / $per_page ) + 1;
$num_pages = ( int ) $num_pages;
$sql_data = "SELECT product.product_id , product.pro_name , product.pro_price , product.pro_description , product.idtrade , product.product_img, category.category_name FROM product INNER JOIN category ON product.category_id = category.category_id
ORDER BY product.product_id = category.category_id ASC LIMIT $page_start, $per_page";
$data_result = mysql_db_query($dbname,$sql_data);
$count = mysql_num_rows($data_result);
}
if ( ( $page > $num_pages ) || ( $page < 0 ) )
print "จำนวน $page มากกว่า $num_pages";
$sql .= " LIMIT $page_start, $per_page";
$result = mysql_query( $sql );
$dbquery = mysql_db_query($dbname,$sql);
$cols = 10;
$c = $cols;
$c --;
?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
<!--
body {
background-image: url(bg_re.gif);
}
-->
</style><table width="100%" border="0"><tr>
<?
if($c == 0) {
$c = $cols;
?>
</tr>
<? } ?>
</table>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>ค้นหาข้อมูลสมาชิก</title>
</head>
<body onload='document.Add1.text_search.focus();'>
<form action='re_product.php' method='get' >
แสดงข้อมูล :
<input name="text_search" type="text" value="<?=$txt_search?>">
<select name="search_type">
<option value='1'<?=($_REQUEST['search_type'] == 1) ? ' selected="selected"' : ''?>>
-คำค้นหา-</option>
<option value='2'<?=($_REQUEST['search_type'] == 2) ? ' selected="selected"' : ''?>>รหัสสินค้า</option>
<option value='3'<?=($_REQUEST['search_type'] == 3) ? ' selected="selected"' : ''?>>ชื่อสินค้า</option>
<option value='4'<?=($_REQUEST['search_type'] == 4) ? ' selected="selected"' : ''?>>หมวดสินค้า</option>
</select>
<input name="cmd_Search" type="submit" id="cmd_Search"value="ค้นหา">
<br />
<br />
รวม <b><?php echo $num_rows; ?></b> แสดงอยู่ <b><?php echo $num_pages; ?></b> หน้า <br />
<table id="member" width="930" border="0" cellspacing="0">
<thead>
<tr>
<th height="64">ลำดับ</th>
<th>รหัสสินค้า</th>
<th>ชื่อสินค้า</th>
<th>ราคา</th>
<th>รายละเอียดสินค้า</th>
<th>ตัวแทนจำหน่าย</th>
<th>หนวดสินค้า</th>
<th>รูปสินค้า</th>
<th>แก้ไข</th>
<th>ลบ</th>
</tr>
</thead>
<tbody>
<?php
$i = 1;
if($data_result)
while($rows = mysql_fetch_array($data_result)) {
//-----------ค้นหาตามคีย์เวิร์ด---------//
$keyword = $_REQUEST['text_search'];// สมมติว่า keyword เท่ากับ text_search
$replace = "<span style='color:red'>{$keyword}</span>"; // ใส่สีให้ keyword
$original = $IDMember; // string ทั้งหมดที่ query Names มา
$IDMember = str_replace($keyword,$replace,$original);
$original = $Names; // string ทั้งหมดที่ query IDMember มา
$Names = str_replace($keyword,$replace,$original);
//------
?>
<tr>
<td class="no"><?=$i?></td>
<td class="product_id"><?=($rows['product_id']) ? sprintf($rows['product_id']) : ' '; ?></td>
<td class="pro_name"><?=($rows['pro_name']) ? sprintf("%49.49s", $rows['pro_name']) : ' '; ?></td>
<td class="pro_price"><?=($rows['pro_price']) ? sprintf($rows['pro_price']) : ' '; ?> บาท</td>
<td class="pro_description"><?=($rows['pro_description']) ? sprintf("%49.49s", $rows['pro_description']):' '; ?></td>
<td class="idtrade">TA<?=($rows['idtrade']) ? sprintf($rows['idtrade']) : ' '; ?></td>
<td class="category_id"><?=($rows['category_name']) ? sprintf($rows['category_name']) : ' '; ?></td>
<td class="img" > <img src="MyResize/<?=$row["product_img"];?>" border="0"></td>
<td><A Href='f_show_mem.php?type=edit&id=<?=$rows['idtrade']?>'><center><img src='images/edit.png' width='16' height='16' border='0'></center></a></td>
<td><a href='f_show_mem.php?IDMember=" .$id . "'><center><img src='images/delete.png' width='16' height='16' border='0'></center></a></td>
</tr>
<?php
$i++;
}
?>
</tbody>
</table>
<br />
<?php
$QA = $_GET;
$QA['page'] = $prev_page;
$QS = http_build_query($QA);
if ( $prev_page )
echo "<a href=\"?$QS\"><<กลับไป </a>";
for ( $i=1; $i<=$num_pages; $i++ )
{
$QA['page'] = $i;
$QS = http_build_query($QA);
if ( $i != $page)
echo "[<a href=\"?$QS\">$i</a>]";
else
echo " <b>$i</b> ";
}
$QA['page'] = $next_page;
$QS = http_build_query($QA);
if ( $page != $num_pages )
echo "<a href=\"?$QS\"> หน้าต่อไป >></a>";
?>
<?php mysql_close();?>
</tr>
</form>Tag : - - - -
Date :
2010-02-10 21:35:34
By :
gofgof
View :
1001
Reply :
2
ขอโทษนะคับที่โพสซ้ำ phpcode ไม่ขึ้นคับ เดียวจะดูยากนะคับ
Code (PHP)
<?php
require_once '../common/config.php';
$page_start=0;
$per_page=20;
$page = @$_REQUEST['page'];
if(isset($_REQUEST['text_search']) && trim($_REQUEST['text_search'])!= ""){
$txt_search = $_REQUEST['text_search'];
$search_type = $_REQUEST['search_type'];
switch ($search_type){
case 2: $where = "product.product_id LIKE '%" . $txt_search . "%'"; break;
case 3: $where = "product.pro_name LIKE '%" . $txt_search . "%'"; break;
case 4: $where = "category.category_name LIKE '%" . $txt_search . "%'"; break;
}
$sql_data_all = "SELECT count(*) FROM product INNER JOIN category ON product.category_id = category.category_id WHERE " .$where. " ORDER BY product.category_id = category.category_id ASC ";
$qr = mysql_db_query($dbname, $sql_data_all);
$num_rows = mysql_result($qr,0);
if ( empty($page) )
$page = 1;
$prev_page = $page - 1;
$next_page = $page + 1;
$page_start = ( $per_page * $page) - $per_page;
if ( $num_rows <= $per_page )
$num_pages = 1;
else if ( ( $num_rows % $per_page ) == 0 )
$num_pages = ( $num_rows / $per_page );
$num_pages = ( $num_rows / $per_page ) + 1;
$num_pages = ( int ) $num_pages;
$sql_data = "SELECT product.product_id ,
product.pro_name ,
product.pro_price ,
product.pro_description ,
product.idtrade ,
product.product_img,
category.category_name
FROM product INNER JOIN category ON product.category_id = category.category_id
WHERE " .$where. " ORDER BY product.category_id = category.category_id ASC LIMIT $page_start, $per_page";
$data_result = mysql_db_query($dbname,$sql_data);
$count = mysql_num_rows($data_result);
echo mysql_error();
}else{
$sql_data_all = "SELECT count(*) FROM product ";
$qr = mysql_db_query($dbname, $sql_data_all);
echo mysql_error();
$num_rows = mysql_result($qr,0);
if ( empty($page) )
$page = 1;
$prev_page = $page - 1;
$next_page = $page + 1;
$page_start = ( $per_page * $page) - $per_page;
if ( $num_rows <= $per_page )
$num_pages = 1;
else if ( ( $num_rows % $per_page ) == 0 )
$num_pages = ( $num_rows / $per_page );
else
$num_pages = ( $num_rows / $per_page ) + 1;
$num_pages = ( int ) $num_pages;
$sql_data = "SELECT product.product_id , product.pro_name , product.pro_price , product.pro_description , product.idtrade , product.product_img, category.category_name FROM product INNER JOIN category ON product.category_id = category.category_id
ORDER BY product.product_id = category.category_id ASC LIMIT $page_start, $per_page";
$data_result = mysql_db_query($dbname,$sql_data);
$count = mysql_num_rows($data_result);
}
if ( ( $page > $num_pages ) || ( $page < 0 ) )
print "จำนวน $page มากกว่า $num_pages";
$sql .= " LIMIT $page_start, $per_page";
$result = mysql_query( $sql );
$dbquery = mysql_db_query($dbname,$sql);
$cols = 10;
$c = $cols;
$c --;
?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
<!--
body {
background-image: url(bg_re.gif);
}
-->
</style><table width="100%" border="0"><tr>
<?
if($c == 0) {
$c = $cols;
?>
</tr>
<? } ?>
</table>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>ค้นหาข้อมูลสมาชิก</title>
</head>
<body onload='document.Add1.text_search.focus();'>
<form action='re_product.php' method='get' >
แสดงข้อมูล :
<input name="text_search" type="text" value="<?=$txt_search?>">
<select name="search_type">
<option value='1'<?=($_REQUEST['search_type'] == 1) ? ' selected="selected"' : ''?>>
-คำค้นหา-</option>
<option value='2'<?=($_REQUEST['search_type'] == 2) ? ' selected="selected"' : ''?>>รหัสสินค้า</option>
<option value='3'<?=($_REQUEST['search_type'] == 3) ? ' selected="selected"' : ''?>>ชื่อสินค้า</option>
<option value='4'<?=($_REQUEST['search_type'] == 4) ? ' selected="selected"' : ''?>>หมวดสินค้า</option>
</select>
<input name="cmd_Search" type="submit" id="cmd_Search"value="ค้นหา">
<br />
<br />
รวม <b><?php echo $num_rows; ?></b> แสดงอยู่ <b><?php echo $num_pages; ?></b> หน้า <br />
<table id="member" width="930" border="0" cellspacing="0">
<thead>
<tr>
<th height="64">ลำดับ</th>
<th>รหัสสินค้า</th>
<th>ชื่อสินค้า</th>
<th>ราคา</th>
<th>รายละเอียดสินค้า</th>
<th>ตัวแทนจำหน่าย</th>
<th>หนวดสินค้า</th>
<th>รูปสินค้า</th>
<th>แก้ไข</th>
<th>ลบ</th>
</tr>
</thead>
<tbody>
<?php
$i = 1;
if($data_result)
while($rows = mysql_fetch_array($data_result)) {
$keyword = $_REQUEST['text_search'];
$replace = "<span style='color:red'>{$keyword}</span>";
$original = $product_id;
$product_id = str_replace($keyword,$replace,$original);
$original = $pro_name;
$pro_name = str_replace($keyword,$replace,$original);
?>
<tr>
<td class="no"><?=$i?></td>
<td class="product_id"><?=($rows['product_id']) ? sprintf($rows['product_id']) : ' '; ?></td>
<td class="pro_name"><?=($rows['pro_name']) ? sprintf("%49.49s", $rows['pro_name']) : ' '; ?></td>
<td class="pro_price"><?=($rows['pro_price']) ? sprintf($rows['pro_price']) : ' '; ?> บาท</td>
<td class="pro_description"><?=($rows['pro_description']) ? sprintf("%49.49s", $rows['pro_description']):' '; ?></td>
<td class="idtrade">TA<?=($rows['idtrade']) ? sprintf($rows['idtrade']) : ' '; ?></td>
<td class="category_id"><?=($rows['category_name']) ? sprintf($rows['category_name']) : ' '; ?></td>
<td class="img" > <img src="MyResize/<?=$row["product_img"];?>" border="0"></td>
<td><A Href='f_show_mem.php?type=edit&id=<?=$rows['idtrade']?>'><center><img src='images/edit.png' width='16' height='16' border='0'></center></a></td>
<td><a href='f_show_mem.php?IDMember=" .$id . "'><center><img src='images/delete.png' width='16' height='16' border='0'></center></a></td>
</tr>
<?php
$i++;
}
?>
</tbody>
</table>
<br />
<?php
$QA = $_GET;
$QA['page'] = $prev_page;
$QS = http_build_query($QA);
if ( $prev_page )
echo "<a href=\"?$QS\"><<กลับไป </a>";
for ( $i=1; $i<=$num_pages; $i++ )
{
$QA['page'] = $i;
$QS = http_build_query($QA);
if ( $i != $page)
echo "[<a href=\"?$QS\">$i</a>]";
else
echo " <b>$i</b> ";
}
$QA['page'] = $next_page;
$QS = http_build_query($QA);
if ( $page != $num_pages )
echo "<a href=\"?$QS\"> หน้าต่อไป >></a>";
?>
<?php mysql_close();?>
</tr>
</form>
Date :
2010-02-10 21:43:21
By :
gofgof
เขียนแบบนี้ก็ไม่ขึ้นคับ แต่คิวรี่ฟิวด์อื่นได้คับ
เขียนอีกแบบหนึ่งคับ
<?php
require_once('class/class_table.php');
require_once('class/class_pager.php');
require_once('class/class_timer.php');
$time = & new Timer();
$time->start();
$str_type = (empty($_POST['search_type'])) ? 'pro_name' : $_POST['search_type'] ;
$str_search = ($_POST['txtSearch']) ? $_POST['txtSearch'] : '';
$key_search = ($_GET['keyword']) ? $_GET['keyword'] : '';
$curr_page = ($_GET['page']) ? $_GET['page'] : '';
if($_POST['search_type'] == 'product_id')
$select_product_id = ' selected="selected"';
else if($_POST['search_type'] == 'pro_name')
$select_pro_name = ' selected="selected"';
else if($_POST['search_type'] == 'category_name')
$select_category_name = ' selected="selected"';
$command = 'SELECT product.product_id , product.pro_name , product.pro_price , product.pro_description , product.idtrade , product.product_img , category.category_name
FROM product INNER JOIN category ON product.category_id = category.category_id ';
$config['url_page'] = 're_product.php?page=';
if(isset($str_search) && empty($key_search)) {
$command = $command." WHERE $str_type like '%{$str_search}%'";
$config['url_page'] = 're_product.php?keyword='.$str_search.'&page=';
}
else if(isset($key_search) && isset($curr_page) && !isset($_POST['txtSearch'])) {
$command = $command." WHERE $str_type like '%{$key_search}%'";
$config['url_page'] = 're_product.php?keyword='.$key_search.'&page=';
}
else if(isset($str_search) && isset($key_search)) {
$command = $command." WHERE $str_type like '%{$str_search}%'";
$config['url_page'] = 're_product.php?keyword='.$str_search.'&page=';
}
$result = mysql_query($command);
$config['all_recs'] = mysql_num_rows($result);
$config['scr_page'] = 5;
$config['per_page'] = 2;
$config['cur_page'] = ($str_search) ? 1 : $_GET['page'];
$config['act_page'] = 'class="current_page"';
$config['css_page'] = 'class="css-pager"';
$config['first'] = '« หน้าแรก';
$config['previous'] = '‹ ก่อนหน้า';
$config['next'] = 'ถัดไป ›';
$config['last'] = 'หน้าสุดท้าย »';
$pager = & new Pager($config);
echo ' <p><strong>จำนวนทั้งหมด : </strong>'.$config['all_recs'].' แถว '.$pager->totalPage().' หน้า</p>';
echo '<form action="" method="post">
<p><label>ค้นหา : </label>
<input type="text" name="txtSearch" id="txtSearch" class="tbx" />
<select name="search_type">
<option value="">-คำค้นหา-</option>
<option value="product_id"'.$select_product_id .'>รหัสสินค้า</option>
<option value="pro_name"'.$select_pro_name.'>ชื่อสินค้า</option>
<option value="category_name"'.$select_category_name.'>หมวดสินค้า</option>
</select>
<input type="submit" name="submit" id="submit" value="ค้นหา" title="ค้นหา" class="btn" /></p>
</form>';
try {
$pager->createPager();
}
catch(Exception $e) { echo $e->getMessage(); }
$attr = 'id="table-id" border="1"';
$head = array('รหัสสินค้า', 'ชื่อสินค้า', 'ราคา', 'รายละเอียดสินค้า' , 'ตัวแทนจำหน่าย' ,'หนวดสินค้า', 'ภาพสินค้า' , 'Edit<br>Product','Edit<br>Trade');
$rcss = array('class="odd"', 'class="even"');
$result = mysql_query($command." ORDER BY product_id ASC LIMIT ".$pager->limitStart().", ".$config['per_page']) or die (mysql_error());
if($result) {
while($rs = mysql_fetch_assoc($result)) {
$data[] = array(
$rs['product_id'],
'<span class="name">'.$rs['pro_name'].'</span>',
'<span class="sname">'.$rs['pro_price'].'</span>',
'<span class="name">'.$rs['pro_description'].'</span>',
'<span class="sname">'.$rs['idtrade'].'</span>',
'<span class="sname">'.$rs['category_name'].'</span>',
'<img src="./MyResize/'.$rs["product_img"].' border="0" />',
'<a href="f_product.php?mode=edit&id='.$rs['product_id'].'"><img src="images/icons/User-Edit.png" border="0" /></a>',
'<a href="f_trade.php?mode=edit&id='.$rs['idtrade'].'"><img src="images/icons/User-Edit.png" border="0" /></a>');
}
}
$table = & new Table($attr, $head, $data, $rcss);
try {
$table ->createTable();
}
catch(Exception $e) { echo $e->getMessage(); }
echo '<br /> This page used time : <span class="txt-red">'.$time->stop().'</span>';
?>
Date :
2010-02-10 22:14:49
By :
gofgof
Load balance : Server 03