doushu7588 2010-02-07 01:35
浏览 21
已采纳

我的SQL查询怎么没有对列进行排序?

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 should look like this

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

  • 写回答

1条回答 默认 最新

  • dse323222 2010-02-07 01:42
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Pwm双极模式H桥驱动控制电机
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题