开发者

Howcome my SQL query is not sorting the column?

开发者 https://www.devze.com 2022-12-19 04:39 出处:网络
http://new.monmouthchineseschool.com/curriculum/cantonese/textbook.php if you take a look at \'C1\' 一 十 十一 十二 十三 二 三 四 五 六 七 八 九

http://new.monmouthchineseschool.com/curriculum/cantonese/textbook.php

if you take a look at 'C1'

一 十 十一 十二 十三 二 三 四 五 六 七 八 九

that is how all the links look like.

this is the mysql db for that class

CREATE TABLE IF NOT EXISTS `mon_textbook` (
  `id` int(11) NOT NULL auto_increment,
  `class` varchar(255) NOT NULL,
  `ch` varchar(255) NOT NULL,
  `sTitle` varchar(255) NOT NULL,
  `fTitle` varchar(255) NOT NULL,
  `text` longtext NOT NULL,
  UNIQUE KEY `id` (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=117 ;

--
-- Dumping data for table `mon_textbook`
--

INSERT INTO `mon_textbook` (`id`, `class`, `ch`, `sTitle`, `fTitle`, `text`) VALUES
(14, 'C1', '1', '一', '第一課', ''),
(15, 'C1', '2', '二', '第二課', ''),
(16, 'C1', '3', '三', '第三課', ''),
(17, 'C1', '4', '四', '第四課', ''),
(18, 'C1', '5', '五', '第五課', ''),
(19, 'C1', '6', '六', '第六課', ''),
(20, 'C1', '7', '七', '第七課', ''),
(21, 'C1', '8', '八', '第八課', ''),
(22, 'C1', '9', '九', '第九課', ''),
(23, 'C1', '10', '十', '第十課', ''),
(24, 'C1', '11', '十一', '第十一課', ''),
(25, 'C1', '12', '十二', '第十二課', ''),
(26, 'C1', '13', '十三', '第十三課', '');

the sql query that calls it

$sql = 'SELECT * FROM '.dbPre.'textbook WHERE `class`="'.$textbookClass[$ii].'" ORDER BY `ch` ASC';

instead of looking like how it is above, it sh开发者_运维问答ould look like this

一 二 三 四 五 六 七 八 九 十 十一 十二 十三


Your ch column contains strings, and they are sorted but alphanumerically, not numerically. Your results are in this order '1 10 11 12 13 2 3 4 ...'

Either change your ch column to an integer type, or cast it to an integer in the ORDER BY. I'd recommend the former.

0

精彩评论

暂无评论...
验证码 换一张
取 消