รบกวนเรื่อง MySql ครับ ใช้งาน Group by กับ order by พร้อมกัน
ช่วย export structure ของ table มาดูหน่อยครับ ไม่เห็นอะไรเลย ตอบยากครับ
Date :
2014-06-19 20:06:40
By :
Chaidhanan
Code (SQL)
-- phpMyAdmin SQL Dump
-- version 2.10.3
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Jun 19, 2014 at 09:38 PM
-- Server version: 5.0.51
-- PHP Version: 5.2.6
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
--
-- Database: `rosyblue`
--
-- --------------------------------------------------------
--
-- Table structure for table `db_mc`
--
CREATE TABLE `db_mc` (
`id_auto` int(11) NOT NULL auto_increment,
`id` varchar(50) NOT NULL,
`b_code` varchar(50) NOT NULL,
`mc_id` varchar(250) NOT NULL,
`invoice` varchar(50) NOT NULL,
`dep_date` varchar(50) NOT NULL,
`price` varchar(50) NOT NULL,
`sup_id` varchar(250) NOT NULL,
`employee_id` varchar(250) NOT NULL,
`sec_id` varchar(250) NOT NULL,
`date` varchar(50) NOT NULL,
`name_add` varchar(250) NOT NULL,
PRIMARY KEY (`id_auto`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=123 ;
--
-- Dumping data for table `db_mc`
--
INSERT INTO `db_mc` VALUES (60, 'TOP-0008', 'FE5612-PO159-30', 'TOP TANG', '11/01/2014', '', '8891.1', 'LANKA ', 'S4742 Thanphitsanu Klinwrathok', 'Top AGS', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (56, 'TOP-0004', 'FE5612-PO159-30', 'TOP TANG', '11/01/2014', '', '8891.1', 'LANKA ', 'S4845 Wikorn Jumpeedong', 'Top AGS', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (59, 'TOP-0007', 'FE5612-PO159-30', 'TOP TANG', '11/01/2014', '', '8891.1', 'LANKA ', 'S4745 Sompong Sentaku', 'Top AGS', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (58, 'TOP-0006', 'FE5612-PO159-30', 'TOP TANG', '11/01/2014', '', '8891.1', 'LANKA ', 'S4739 Siaykwan Watphatoumon', 'Top AGS', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (57, 'TOP-0005', 'FE5612-PO159-30', 'TOP TANG', '11/01/2014', '', '8891.1', 'LANKA ', 'S4962 Nawarat Kladsup', 'Top AGS', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (55, 'TOP-0003', 'FE5612-PO159-30', 'TOP TANG', '11/01/2014', '', '8891.1', 'LANKA ', 'S4923 Onuma Supchawna', 'Top AGS', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (53, 'TOP-0001', 'FE5612-PO159-30', 'TOP TANG', '11/01/2014', '', '8891.1', 'LANKA ', 'S4599 Proymanee Yeepan', 'Top AGS', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (54, 'TOP-0002', 'FE5612-PO159-30', 'TOP TANG', '11/01/2014', '', '8891.1', 'LANKA ', 'S4422 ThatPhong Chaisue', 'Top AGS', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (52, 'TS-0012', 'FE5601-SCK08-20', 'TANG T/S', '11/01/2013', '-', '2151.1', 'LANKA ', 'S3431 Sompob Neamyim', 'Bot VG manual', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (51, 'TS-0011', 'FE5601-SCK08-20', 'TANG T/S', '11/01/2013', '-', '2151.1', 'LANKA ', 'S3431 Sompob Neamyim', 'Bot VG manual', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (50, 'TS-0007', 'FE5601-SCK08-20', 'TANG T/S', '11/01/2013', '-', '2151.1', 'LANKA ', 'S4913 Prasit Sansing', 'Preparation Treatment', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (49, 'TS-0005', 'FE5601-SCK08-20', 'TANG T/S', '11/01/2013', '-', '2151.1', 'LANKA ', 'S4771 Thongchai Sodsri', 'Preparation Treatment', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (48, 'BOT-0001', 'FE5704-PP075-02', 'BOTTOM TANG ', '17/05/2014', '-', '22128.7', 'ADRI ', 'S4913 Prasit Sansing', 'Preparation Treatment', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (61, 'TOP-0009', 'FE5612-PO159-30', 'TOP TANG', '11/01/2014', '', '8891.1', 'LANKA ', 'S4738 Suriphon Yimthapho', 'Top AGS', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (62, 'TOP-0010', 'FE5612-PO159-30', 'TOP TANG', '11/01/2014', '', '8891.1', 'LANKA ', 'S4738 Suriphon Yimthapho', 'Top AGS', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (63, 'TOP-0011', 'FE5612-PO159-30', 'TOP TANG', '11/01/2014', '', '8891.1', 'LANKA ', 'S4724 Thanphitsanu Klinkrathok', 'Top AGS', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (64, 'TOP-0012', 'FE5612-PO159-30', 'TOP TANG', '11/01/2014', '', '8891.1', 'LANKA ', 'S4744 Waranon Sareekham', 'Top AGS', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (65, 'TOP-0013', 'FE5612-PO159-30', 'TOP TANG', '11/01/2014', '', '8891.1', 'LANKA ', 'A776 Sunisa Sritan', 'Top AGS', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (66, 'TOP-0014', 'FE5612-PO159-30', 'TOP TANG', '11/01/2014', '', '8891.1', 'LANKA ', 'A875 Anchalee Kamlue', 'Top AGS', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (67, 'TOP-0015', 'FE5612-PO159-30', 'TOP TANG', '11/01/2014', '', '8891.1', 'LANKA ', 'A98 Wandee Kumsaeng', 'Top AGS', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (68, 'TOP-0016', 'FE5612-PO159-30', 'TOP TANG', '11/01/2014', '', '8891.1', 'LANKA ', 'S2089 Narunart Sudharn', 'Top AGS', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (69, 'TOP-0017', 'FE5612-PO159-30', 'TOP TANG', '11/01/2014', '', '8891.1', 'LANKA ', 'P538 Yuphin Keawjaidee', 'Top AGS', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (70, 'TOP-0018', 'FE5612-PO159-30', 'TOP TANG', '11/01/2014', '', '8891.1', 'LANKA ', 'P525 Wipakul Malila', 'Top AGS', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (71, 'TOP-0019', 'FE5612-PO159-30', 'TOP TANG', '11/01/2014', '', '8891.1', 'LANKA ', 'S0552 Montakarn Neampuang', 'Top AGS', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (72, 'TOP-0020', 'FE5612-PO159-30', 'TOP TANG', '11/01/2014', '', '8891.1', 'LANKA ', 'A377 Thavorn Soysamang', 'Top AGS', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (73, 'TOP-0021', 'FE5612-PO159-30', 'TOP TANG', '11/01/2014', '', '8891.1', 'LANKA ', 'S0977 Jintana Puangtong', 'Top AGS', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (74, 'TOP-0022', 'FE5612-PO159-30', 'TOP TANG', '11/01/2014', '', '8891.1', 'LANKA ', 'A43 Jampa Nuammee', 'Top AGS', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (75, 'TOP-0023', 'FE5612-PO159-30', 'TOP TANG', '11/01/2014', '', '8891.1', 'LANKA ', 'S2843 Jantra Khayaiseang', 'Top AGS', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (76, 'TOP-0024', 'FE5612-PO159-30', 'TOP TANG', '11/01/2014', '', '8891.1', 'LANKA ', 'S2647 Wasana Norralak', 'Top AGS', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (77, 'TOP-0025', 'FE5612-PO159-30', 'TOP TANG', '11/01/2014', '', '8891.1', 'LANKA ', 'S2317 Juthamas Paypanas', 'Top AGS', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (78, 'TOP-0026', 'FE5612-PO159-30', 'TOP TANG', '11/01/2014', '', '8891.1', 'LANKA ', 'S3996 Jakkaphon Boonma', 'Top AGS', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (79, 'TOP-0027', 'FE5612-PO159-30', 'TOP TANG', '11/01/2014', '', '8891.1', 'LANKA ', 'S3996 Jakkaphon Boonma', 'Top AGS', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (80, 'TOP-0028', 'FE5612-PO159-30', 'TOP TANG', '11/01/2014', '', '8891.1', 'LANKA ', 'S3430 Kritsana Puam', 'Top AGS', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (81, 'TOP-0029', 'FE5612-PO159-30', 'TOP TANG', '11/01/2014', '', '8891.1', 'LANKA ', 'S3430 Kritsana Puam', 'Top AGS', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (82, 'TOP-0030', 'FE5612-PO159-30', 'TOP TANG', '11/01/2014', '', '8891.1', 'LANKA ', 'S3701 Pranee Krokpueak', 'Top AGS', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (83, 'TOP-0031', 'FE5601-ID06-37', 'TANG TOP', '11/01/2013', '', '4609.5', 'LANKA ', 'S3701 Pranee Krokpueak', 'Top AGS', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (84, 'TOP-0032', 'FE5601-ID06-37', 'TANG TOP', '11/01/2013', '', '4609.5', 'LANKA ', 'S3659 Inkaporn Thongampai', 'Top AGS', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (85, 'TOP-0033', 'FE5601-ID06-37', 'TANG TOP', '11/01/2013', '', '4609.5', 'LANKA ', 'S3554 Kreingkrai Lamoon', 'Top AGS', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (86, 'TOP-0034', 'FE5601-ID06-37', 'TANG TOP', '11/01/2013', '', '4609.5', 'LANKA ', 'S1740 Weerapong Sriraksa', 'Top AGS', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (87, 'TOP-0035', 'FE5601-ID06-37', 'TANG TOP', '11/01/2013', '', '4609.5', 'LANKA ', 'S6716 Chanthima Phomain', 'Top AGS', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (88, 'TOP-0036', 'FE5601-ID06-37', 'TANG TOP', '11/01/2013', '', '4609.5', 'LANKA ', 'S6727 Niyada Winker', 'Top AGS', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (89, 'TOP-0037', 'FE5601-ID06-37', 'TANG TOP', '11/01/2013', '', '4609.5', 'LANKA ', 'S6729 Nattawit Poparyom', 'Top AGS', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (90, 'TOP-0038', 'FE5601-ID06-37', 'TANG TOP', '11/01/2013', '', '4609.5', 'LANKA ', 'S6648 Monrudee Suksaeng', 'Top AGS', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (91, 'TOP-0039', 'FE5601-ID06-37', 'TANG TOP', '11/01/2013', '', '4609.5', 'LANKA ', 'S6720 Narirat Neamchowna', 'Top AGS', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (92, 'TOP-0040', 'FE5601-ID06-37', 'TANG TOP', '11/01/2013', '', '4609.5', 'LANKA ', 'S6707 Pimporn Phonkaew', 'Top AGS', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (93, 'TOP-0041', 'FE5601-ID06-37', 'TANG TOP', '11/01/2013', '', '4609.5', 'LANKA ', 'S6731 Wijittri Pattanatawamat', 'Top AGS', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (94, 'TOP-0042', 'FE5601-ID06-37', 'TANG TOP', '11/01/2013', '', '4609.5', 'LANKA ', 'S6647 Thawatchai Pongpeaw', 'Top AGS', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (95, 'TOP-0043', 'FE5601-ID06-37', 'TANG TOP', '11/01/2013', '', '4609.5', 'LANKA ', 'S6572 Sorawit Meejan', 'Top AGS', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (96, 'TOP-0044', 'FE5601-ID06-37', 'TANG TOP', '11/01/2013', '', '4609.5', 'LANKA ', 'S6570 Chintana Phakphrom', 'Top AGS', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (97, 'TOP-0045', 'FE5601-ID06-37', 'TANG TOP', '11/01/2013', '', '4609.5', 'LANKA ', 'S6557 Yonlada Buakham', 'Top AGS', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (98, 'TOP-0046', 'FE5601-ID06-37', 'TANG TOP', '11/01/2013', '', '4609.5', 'LANKA ', 'S6145 Nanthaka Kumchoo', 'Top AGS', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (99, 'TOP-0047', 'FE5601-ID06-37', 'TANG TOP', '11/01/2013', '', '4609.5', 'LANKA ', 'S5170 Wannipha Rueathamin', 'Top AGS', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (100, 'TOP-0048', 'FE5601-ID06-37', 'TANG TOP', '11/01/2013', '', '4609.5', 'LANKA ', 'S5174 Vijittar Machaeng', 'Top AGS', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (101, 'TOP-0049', 'FE5601-ID06-37', 'TANG TOP', '11/01/2013', '', '4609.5', 'LANKA ', 'S5292 Natthaphong Taphaophong', 'Top AGS', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (102, 'TOP-0050', 'FE5601-ID06-37', 'TANG TOP', '11/01/2013', '', '4609.5', 'LANKA ', 'S5291 Prasong Khongwangthong', 'Top AGS', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (103, 'TOP-0051', 'FE5601-ID06-37', 'TANG TOP', '11/01/2013', '', '4609.5', 'LANKA ', 'S6532 Sukanya Thuemkum', 'Top AGS', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (104, 'TOP-0052', 'FE5601-ID06-37', 'TANG TOP', '11/01/2013', '', '4609.5', 'LANKA ', 'S6479 Saithip Kerdlap', 'Top AGS', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (105, 'TOP-0053', 'FE5601-ID06-37', 'TANG TOP', '11/01/2013', '', '4609.5', 'LANKA ', 'S6531 Sakulthip Khunnarong', 'Top AGS', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (106, 'TOP-0054', 'FE5601-ID06-37', 'TANG TOP', '11/01/2013', '', '4609.5', 'LANKA ', 'S6291 Phimwalan Khunnarong ', 'Top AGS', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (107, 'TOP-0055', 'FE5601-ID06-37', 'TANG TOP', '11/01/2013', '', '4609.5', 'LANKA ', 'S6284 Witsarut Seebun', 'Top AGS', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (108, 'TOP-0056', 'FE5601-ID06-37', 'TANG TOP', '11/01/2013', '', '4609.5', 'LANKA ', 'S6243 Nuannapha Netrung', 'Top AGS', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (109, 'TOP-0057', 'FE5601-ID06-37', 'TANG TOP', '11/01/2013', '', '4609.5', 'LANKA ', 'S6294 Nattaya Sittiwong', 'Top AGS', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (110, 'TOP-0058', 'FE5601-ID06-37', 'TANG TOP', '11/01/2013', '', '4609.5', 'LANKA ', 'S6293 Minnaphat Krongthong', 'Top AGS', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (111, 'TOP-0059', 'FE5601-ID06-37', 'TANG TOP', '11/01/2013', '', '4609.5', 'LANKA ', 'S6299 Chainarai Suwannathep', 'Top AGS', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (112, 'TOP-0060', 'FE5601-ID06-37', 'TANG TOP', '11/01/2013', '', '4609.5', 'LANKA ', 'S6638 Panatthida Thajai ', 'Top AGS', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (113, 'TOP-0061', 'FE5601-ID06-37', 'TANG TOP', '11/01/2013', '', '4609.5', 'LANKA ', 'S6639 Orathai Nothakote', 'Top AGS', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (114, 'TOP-0062', 'FE5601-ID06-37', 'TANG TOP', '11/01/2013', '', '4609.5', 'LANKA ', 'S6640 Onuma Rattanaprom', 'Top AGS', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (115, 'TOP-0063', 'FE5601-ID06-37', 'TANG TOP', '11/01/2013', '', '4609.5', 'LANKA ', 'S2893 Rodjana Somboon', 'Top AGS', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (116, 'TOP-0064', 'FE5601-ID06-37', 'TANG TOP', '11/01/2013', '', '4609.5', 'LANKA ', 'S3704 Aronya Niyomyat', 'Top AGS', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (117, 'TOP-0065', 'FE5601-ID06-37', 'TANG TOP', '11/01/2013', '', '4609.5', 'LANKA ', 'S4291 Walipron Prayseang', 'Top AGS', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (118, 'TOP-0066', 'FE5601-ID06-37', 'TANG TOP', '11/01/2013', '', '4609.5', 'LANKA ', 'S4848 Chaiyasit Koedaiam', 'Top AGS', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (119, 'TOP-0067', 'FE5601-ID06-37', 'TANG TOP', '11/01/2013', '', '4609.5', 'LANKA ', 'S4295 Naphapron Sriphon', 'Top AGS', '16/06/2014', 'ANN');
INSERT INTO `db_mc` VALUES (122, 'TOP-0067', 'FE5601-ID06-37', 'TANG TOP', '11/01/2013', '', '4609.5', 'LANKA ', 'S4295 Naphapron Sriphon', 'RM', '19/06/2014 20:42:59', 'Tranfer by :admin');
INSERT INTO `db_mc` VALUES (121, 'TOP-0067', 'FE5601-ID06-37', 'TANG TOP', '11/01/2013', '', '4609.5', 'LANKA ', 'S4295 Naphapron Sriphon', 'SCK', '19/06/2014 16:55:07', 'Tranfer by :admin');
รบกวนด้วยครับ
Date :
2014-06-19 20:38:43
By :
jambon2499
ถ้าอยาก ให้ โชว์ต้อง ใส่ max(id_auto) ครับ เป็นการบังคับให้แสดงครับ
ถ้าไม่บังคับ group by มันจะ โชว์ record แรกที่เจอ ครับ
ส่วน order by จะทำหลังจาก ได้ result ของ group by มาแล้วครับ
ประวัติการแก้ไข 2014-06-19 21:14:40
Date :
2014-06-19 21:12:21
By :
Chaidhanan
Code (SQL)
select id,b_code,mc_id,sec_id,invoice, max(id_auto) from $tb where id like '%$keyword%' or b_code like '%$keyword%' Group by id desc
ลองแบบนี้ก็ยังเหมือนเดิมครับผม
Date :
2014-06-19 21:22:03
By :
jambon2499
id_auto ล่าสุดของอะไรครับ มัน มี where clause และ group by เป็นตัวบังคับให้แสดง
max(id_auto) จะแสดง ค่าสูงสุดของ group by id ครับ
id 'TOP-0067' ก็จะได้ id_auto=122 ครับ สำหรับ id อื่นๆ ก็จะได้ค่าสูงสุด ของ id_auto นั้นๆไปครับ
ลองเอา statement นี้ ไป query ใน phpmyadmin ดูครับ ยังไม่ต้องใส่ where ครับ
select *, max(id_auto) from db_mc where 1 Group by id ORDER BY id_auto DESC
ประวัติการแก้ไข 2014-06-19 21:38:43
Date :
2014-06-19 21:29:22
By :
Chaidhanan
Code (SQL)
$sql="select *,max(id_auto) from $tb where id like '%$keyword%' or b_code like '%$keyword%' Group by id ";
ยังดึงค่าแรกเหมือนเดิมอะครับอาจารย์
Date :
2014-06-19 21:43:59
By :
jambon2499
select *, max(id_auto) from db_mc where 1 Group by id ORDER BY id_auto DESC
มันต้องได้ตามนี้ครับ ผมลองเอามาใส่ในเครื่องผม
ดูที่ ฟีลด์หลังสุดครับ max(id_auto)
ประวัติการแก้ไข 2014-06-19 21:51:39
Date :
2014-06-19 21:50:40
By :
Chaidhanan
ผมว่า คุณไปดู field id_auto ไม่ได้ดู field max(id_auto) ใช่ไหมครับ
Date :
2014-06-19 21:53:52
By :
Chaidhanan
max(id)=122 sec_id ต้อง เป็ฯ RM นะครับ
Date :
2014-06-19 21:54:28
By :
jambon2499
sec_id TOP AGS เป็นของ 119
Date :
2014-06-19 21:56:54
By :
jambon2499
echo statement มาดูครับ ผมจะได้เอามาลอง ดู
echo $sql; มาดูทีครับ
Date :
2014-06-19 21:57:40
By :
Chaidhanan
Date :
2014-06-19 21:59:24
By :
jambon2499
Code (PHP)
<?
$keyword=$_POST["keyword"];
if($keyword==""){
$keyword=$_GET["keyword"];
}
include "connect.php";
$tb="db_mc";
$sql="select *, max(id_auto) from $tb where 1 Group by id ORDER BY id_auto DESC";
$Per_Page =10; // แสดงหน้าละ 12
if(!$Page)
$Page=1;
$Prev_Page = $Page-1;
$Next_Page = $Page+1;
$result = mysql_query($sql);
$Page_start = ($Per_Page*$Page)-$Per_Page;
$Num_Rows = mysql_num_rows($result);
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;
if(($Page>$Num_Pages) || ($Page<0))
print "<center><b>จำนวน $Page มากกว่า $Num_Pages ยังไม่มีข้อความ<b></center>";
$sql = "select *, max(id_auto) from $tb where 1 Group by id ORDER BY id_auto DESC LIMIT $Page_start , $Per_Page";
//ส่วนแสดงผล
$result = mysql_query($sql);
$a=0;
While($row= mysql_fetch_array($result)){
$id = $row["id"];
$id_auto = $row["id_auto"];
$b_code = $row["b_code"];
$mc_id = $row["mc_id"];
$sec_id = $row["sec_id"];
$invoice = $row["invoice"];
$date = $row["date"];
$a=$a+1;
if($bg == "#edeff4") { //ส่วนของการ สลับสี
$bg = "#FFFFFF";
} else {
$bg = "#edeff4";
}
?>
Date :
2014-06-19 22:00:38
By :
jambon2499
อ้อ เข้าใจแล้ว ครับ ตามที่ต้องการ ไม่สามารถ เขียน statement ชั้นเดียวได้ครับ
ต้องทำแบบนี้ครับ
SELECT d.* FROM (select max(id_auto) mx_id from db_mc group by id) idx left join db_mc d on idx.mx_id=d.id_auto
where id like '%$keyword%' or b_code like '%$keyword%'
ลองดูครับ
Date :
2014-06-19 22:29:46
By :
Chaidhanan
Code (SQL)
$sql = "select DISTINCT id from $tb ORDER BY id_auto DESC LIMIT $Page_start , $Per_Page";
//ส่วนแสดงผล
$result = mysql_query($sql);
$a=0;
While($row= mysql_fetch_array($result)){
$id = $row["id"];
$id_auto = $row["id_auto"];
$b_code = $row["b_code"];
$mc_id = $row["mc_id"];
$sec_id = $row["sec_id"];
$invoice = $row["invoice"];
$date = $row["date"];
$a=$a+1;
$tb2="db_mc";
$sql2="select * from $tb2 where id='$id'";
$result2 = mysql_query($sql2);
While($row2= mysql_fetch_array($result2)){
$id = $row2["id"];
$id_auto = $row2["id_auto"];
$b_code = $row2["b_code"];
$mc_id = $row2["mc_id"];
$sec_id = $row2["sec_id"];
$invoice = $row2["invoice"];
$date = $row2["date"];
}
ได้แล้วครับผม......แต่โค๊ดยาวนิดครับ แต่ได้ผลลัพธ์ที่ต้องการคับ
Date :
2014-06-19 22:30:23
By :
jambon2499
Date :
2014-06-19 22:32:11
By :
Chaidhanan
Code (SQL)
SELECT d.* FROM (select max(id_auto) mx_id from db_mc group by id) idx left join db_mc d on idx.mx_id=d.id_auto
where id like '%$keyword%' or b_code like '%$keyword%'
ของอาจารย์ใช้งานได้เหมือนกัน ครับ ขอบพระคุณครับ
Date :
2014-06-19 22:39:11
By :
jambon2499
Load balance : Server 01