|
|
|
เรียกใช้ function ซ้อน function แล้วไม่โหลดหน้าเลยครับ ช่วยดูให้ที |
|
|
|
|
|
|
|
Code ทั้งหมด ครับ
Code (PHP)
<?php
include_once('config.php');
if(!session_is_registered('username')){
echo "<script>window.location='login.php';</script>";
exit();
}
if(!empty($_POST['lang']))
$_SESSION['language'] = $_POST['lang'];
if(!session_is_registered('language')){
$_SESSION['language'] = 1;
}else{
$_SESSION['language'];
}
function getPath($cid,$lang) {
$query = mysql_query("SELECT name, parent_id FROM category c LEFT JOIN category_description cd ON (c.category_id = cd.category_id) WHERE c.category_id = '" . (int)$cid . "' AND cd.language_id = '" . (int)$lang . "' ORDER BY c.sort_order, cd.name ASC");
$category_info = mysql_fetch_array($query);
if ($category_info['parent_id']) {
return getPath($category_info['parent_id'], $lang) . " > " . $category_info['name'];
} else {
return $category_info['name'];
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form action="#" method="post" name="deleteForm" id="deleteForm">
<input type="hidden" name="type" id="type" value="delete">
<table cellpadding="2" cellspacing="2" width="100%" border="1">
<tr>
<td colspan="3">หมวดหมู่สินค้า</td>
<td><input type="button" name="add" value="เพิ่ม" onclick="window.location='index.php?CON=category.add'"> <input type="submit" name="Submit" value="ลบ"></td>
</tr>
<tr>
<td width="3%"><input type="checkbox" name="checkall" id="checkall" value="Y" onclick="ClickCheckAll(this);"></td>
<td>ชื่อประเภทสินค้า</td>
<td width="15%">ลำดับการแสดง</td>
<td width="10%">การกระทำ</td>
</tr>
<?
$sql = "SELECT * FROM category c LEFT JOIN category_description cd ON (c.category_id = cd.category_id) WHERE language_id = '$_SESSION[language]' ORDER BY c.sort_order,cd.name ASC";
$mresult = mysql_query($sql);
$key = 1;
while($mdata = mysql_fetch_array($mresult)){
$i++;
if($current_page==1){
$no=$i;
}else{
$no=$i+($current_page-1)*$per_page;
}
$category_id = $mdata['category_id'];
$image = $mdata['image'];
$parent_id = $mdata['parent_id'];
$sort_order = $mdata['sort_order'];
$status = $mdata['status'];
$colorMousOver = "#ffffdd";
if($i%2==1){
$colorTR1 = "#ffffff";
}else{
$colorTR1 = "#f9f9f9";
}
?>
<tr height="40" bgcolor="<?=$colorTR1;?>" onmouseover="this.style.backgroundColor='<?=$colorMousOver;?>'" onmouseout="this.style.backgroundColor='<?=$colorTR1;?>'">
<td><input name="item_id[]" id="item_id<?=$i;?>" type="checkbox" value="<?=$category_id;?>" /></td>
<td><?=getPath($category_id,$_SESSION['language']);?></td>
<td><?=$sort_order;?></td>
<td>[<a href="index.php?CON=category.edit&cid=<?=$category_id;?>">แก้ไข</a>]</td>
</tr>
<?
$key++;
}
?>
</table>
</form>
</body>
</html>
ฐานข้อมูลที่เกี่ยวข้อง
-- phpMyAdmin SQL Dump
-- version 2.10.3
-- http://www.phpmyadmin.net
--
-- โฮสต์: localhost
-- เวลาในการสร้าง: 07 พ.ย. 2011 น.
-- รุ่นของเซิร์ฟเวอร์: 5.0.51
-- รุ่นของ PHP: 5.2.6
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
--
-- ฐานข้อมูล: `tests`
--
-- --------------------------------------------------------
--
-- โครงสร้างตาราง `category`
--
CREATE TABLE `category` (
`category_id` int(11) NOT NULL auto_increment,
`image` varchar(255) collate utf8_unicode_ci default NULL,
`parent_id` int(11) NOT NULL default '0',
`sort_order` int(3) NOT NULL default '0',
`date_added` datetime NOT NULL default '0000-00-00 00:00:00',
`date_modified` datetime NOT NULL default '0000-00-00 00:00:00',
`status` int(1) NOT NULL default '1',
PRIMARY KEY (`category_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=44 ;
--
-- dump ตาราง `category`
--
INSERT INTO `category` VALUES (25, '', 0, 3, '2009-01-31 01:04:25', '2010-03-21 15:30:07', 1);
INSERT INTO `category` VALUES (27, '', 20, 2, '2009-01-31 01:55:34', '2010-03-21 15:29:49', 1);
INSERT INTO `category` VALUES (20, '', 27, 1, '2009-01-05 21:49:43', '2011-10-17 11:17:22', 1);
INSERT INTO `category` VALUES (24, '', 0, 5, '2009-01-20 02:36:26', '2010-03-21 15:30:50', 1);
INSERT INTO `category` VALUES (18, '', 18, 2, '2009-01-05 21:49:15', '2011-10-17 11:17:50', 1);
INSERT INTO `category` VALUES (17, '', 0, 4, '2009-01-03 21:08:57', '2010-03-21 15:30:44', 1);
INSERT INTO `category` VALUES (28, '', 25, 1, '2009-02-02 13:11:12', '2010-03-21 15:30:17', 1);
INSERT INTO `category` VALUES (26, '', 20, 1, '2009-01-31 01:55:14', '2010-03-21 15:29:42', 1);
INSERT INTO `category` VALUES (29, '', 25, 1, '2009-02-02 13:11:37', '2010-03-21 15:30:12', 1);
INSERT INTO `category` VALUES (30, '', 25, 1, '2009-02-02 13:11:59', '2010-03-21 15:30:22', 1);
INSERT INTO `category` VALUES (31, '', 25, 1, '2009-02-03 14:17:24', '2010-03-21 15:30:27', 1);
INSERT INTO `category` VALUES (32, '', 25, 1, '2009-02-03 14:17:34', '2010-03-21 15:30:35', 1);
INSERT INTO `category` VALUES (33, '', 0, 6, '2009-02-03 14:17:55', '2010-03-21 15:30:55', 1);
INSERT INTO `category` VALUES (34, '', 0, 7, '2009-02-03 14:18:11', '2010-03-21 15:31:01', 1);
INSERT INTO `category` VALUES (35, '', 25, 0, '2011-10-17 11:19:53', '2011-10-17 11:19:53', 1);
INSERT INTO `category` VALUES (36, '', 35, 0, '2011-10-17 11:21:40', '2011-10-17 11:21:40', 1);
INSERT INTO `category` VALUES (37, '', 36, 0, '2011-10-17 17:57:12', '2011-10-17 17:57:12', 1);
INSERT INTO `category` VALUES (38, '', 37, 0, '2011-10-17 17:57:37', '2011-10-17 17:57:37', 1);
INSERT INTO `category` VALUES (39, '', 38, 0, '2011-10-17 18:03:42', '2011-10-17 18:03:42', 1);
INSERT INTO `category` VALUES (40, '', 39, 0, '2011-10-17 18:04:04', '2011-10-17 18:04:04', 1);
INSERT INTO `category` VALUES (41, '', 39, 0, '2011-10-17 18:05:11', '2011-10-17 18:05:11', 1);
INSERT INTO `category` VALUES (42, '', 25, 0, '2011-10-19 15:11:36', '2011-10-19 15:11:36', 1);
INSERT INTO `category` VALUES (43, '', 0, 0, '2011-10-19 15:36:51', '2011-10-19 15:37:00', 1);
-- --------------------------------------------------------
--
-- โครงสร้างตาราง `category_description`
--
CREATE TABLE `category_description` (
`category_id` int(11) NOT NULL,
`language_id` int(11) NOT NULL,
`name` varchar(32) collate utf8_unicode_ci NOT NULL default '',
`meta_description` varchar(255) collate utf8_unicode_ci NOT NULL,
`description` text collate utf8_unicode_ci NOT NULL,
PRIMARY KEY (`category_id`,`language_id`),
KEY `name` (`name`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
--
-- dump ตาราง `category_description`
--
INSERT INTO `category_description` VALUES (18, 2, 'Laptops & Notebooks', '', '');
INSERT INTO `category_description` VALUES (28, 1, 'Monitors', '', '');
INSERT INTO `category_description` VALUES (20, 2, 'Desktops', 'Example of category description', '<p>\r\n Example of category description text</p>\r\n');
INSERT INTO `category_description` VALUES (34, 1, 'MP3 Players', '', '');
INSERT INTO `category_description` VALUES (33, 1, 'Cameras', '', '');
INSERT INTO `category_description` VALUES (32, 1, 'Web Cameras', '', '');
INSERT INTO `category_description` VALUES (31, 1, 'Scanners', '', '');
INSERT INTO `category_description` VALUES (30, 1, 'Printers', '', '');
INSERT INTO `category_description` VALUES (29, 1, 'Mice and Trackballs', '', '');
INSERT INTO `category_description` VALUES (27, 1, 'Mac', '', '');
INSERT INTO `category_description` VALUES (26, 1, 'PC', '', '');
INSERT INTO `category_description` VALUES (17, 1, 'Software', '', '');
INSERT INTO `category_description` VALUES (25, 1, 'Components', '', '');
INSERT INTO `category_description` VALUES (24, 1, 'Phones & PDAs', '', '');
INSERT INTO `category_description` VALUES (18, 1, 'Laptops & Notebooks', '', '');
INSERT INTO `category_description` VALUES (28, 2, 'Monitors', '', '');
INSERT INTO `category_description` VALUES (20, 1, 'Desktops', 'Example of category description', '<p>\r\n Example of category description text</p>\r\n');
INSERT INTO `category_description` VALUES (34, 2, 'MP3 Players', '', '');
INSERT INTO `category_description` VALUES (33, 2, 'Cameras', '', '');
INSERT INTO `category_description` VALUES (32, 2, 'Web Cameras', '', '');
INSERT INTO `category_description` VALUES (31, 2, 'Scanners', '', '');
INSERT INTO `category_description` VALUES (30, 2, 'Printers', '', '');
INSERT INTO `category_description` VALUES (29, 2, 'Mice and Trackballs', '', '');
INSERT INTO `category_description` VALUES (27, 2, 'Mac', '', '');
INSERT INTO `category_description` VALUES (26, 2, 'PC', '', '');
INSERT INTO `category_description` VALUES (17, 2, 'Software', '', '');
INSERT INTO `category_description` VALUES (25, 2, 'Components', '', '');
INSERT INTO `category_description` VALUES (24, 2, 'Phones & PDAs', '', '');
INSERT INTO `category_description` VALUES (35, 1, 'test', '', '');
INSERT INTO `category_description` VALUES (35, 2, 'ทดสอบ', '', '');
INSERT INTO `category_description` VALUES (36, 1, 'test2', 'test', '');
INSERT INTO `category_description` VALUES (36, 2, 'ทดสอบ2', '', '');
INSERT INTO `category_description` VALUES (37, 1, 'test3', '', '');
INSERT INTO `category_description` VALUES (37, 2, 'ทดสอบ 3', '', '');
INSERT INTO `category_description` VALUES (38, 1, 'test4', '', '');
INSERT INTO `category_description` VALUES (38, 2, 'ทดสอบ 4', '', '');
INSERT INTO `category_description` VALUES (39, 1, 'test 5', '', '');
INSERT INTO `category_description` VALUES (39, 2, 'ทดสอบ 5', '', '');
INSERT INTO `category_description` VALUES (40, 1, 'test 6 ', '', '');
INSERT INTO `category_description` VALUES (40, 2, 'ทดสอบ 6', '', '');
INSERT INTO `category_description` VALUES (41, 1, 'test 7', '', '');
INSERT INTO `category_description` VALUES (41, 2, 'ทดสอบ 7', '', '');
INSERT INTO `category_description` VALUES (42, 1, 'test50', '', '');
INSERT INTO `category_description` VALUES (42, 2, 'ทดสอบ 50', '', '');
INSERT INTO `category_description` VALUES (43, 2, 'twtwtw', '', '');
INSERT INTO `category_description` VALUES (43, 1, 'twtwtw', '', '');
หรือใครมีวิธีอื่นแนะนำให้ทีนะครับ ขอบคุณครับ
|
|
|
|
|
Date :
2011-11-07 12:24:17 |
By :
wacharak |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
table category
category_id 20 parent_id 27
category_id 27 parent_id 20
มันวนอยู่ 2 record นี้และ
|
|
|
|
|
Date :
2011-11-08 00:45:34 |
By :
ผ่านมา |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|