如何使用PHP和MySQL对表值进行排序?

时间:2016-04-23 10:42:22

标签: php mysql

我需要使用MySQL和PHP使用一个订单获取MySQL表值。我在下面提供我的表格。

db_cat:

id     cat_name   cat_id     order_no

1       aaa        10          1

2       ggg        10          30

3        fff       10           11


4      sss         10           12

5      ddd         10            5

这里我尝试使用查询按照order_no列值获取数据:

select * from db_cat where cat_id='10' order by order_no asc

但它给了我错误的订单数据,如(11,12,30,1,5),我应该得到这样的订单数据(1,5,11,12,30)。

我的order_no数据类型为varchar

1 个答案:

答案 0 :(得分:4)

您可以按顺序使用强制转换

a:5:{i:0;s:233:"
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'dme_dubai.log_visitor' doesn't exist, query was: 
INSERT INTO `log_visitor` (`session_id`, `first_visit_at`, `last_visit_at`, `last_url_id`, `store_id`) VALUES (?, ?, ?, ?, ?)
";i:1;s:2752:"
#0 /home/dme/public_html/lib/Varien/Db/Statement/Pdo/Mysql.php(110): Zend_Db_Statement_Pdo->_execute(Array)
#1 /home/dme/public_html/app/code/core/Zend/Db/Statement.php(291): Varien_Db_Statement_Pdo_Mysql->_execute(Array)
#2 /home/dme/public_html/lib/Zend/Db/Adapter/Abstract.php(480): Zend_Db_Statement->execute(Array)
#3 /home/dme/public_html/lib/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query('INSERT INTO `lo...', Array)
#4 /home/dme/public_html/lib/Varien/Db/Adapter/Pdo/Mysql.php(428): Zend_Db_Adapter_Pdo_Abstract->query('INSERT INTO `lo...', Array)
#5 /home/dme/public_html/lib/Zend/Db/Adapter/Abstract.php(576): Varien_Db_Adapter_Pdo_Mysql->query('INSERT INTO `lo...', Array)
#6 /home/dme/public_html/app/code/core/Mage/Core/Model/Resource/Db/Abstract.php(453): Zend_Db_Adapter_Abstract->insert('log_visitor', Array)
#7 /home/dme/public_html/app/code/core/Mage/Core/Model/Abstract.php(318): Mage_Core_Model_Resource_Db_Abstract->save(Object(Mage_Log_Model_Visitor))
#8 /home/dme/public_html/app/code/core/Mage/Log/Model/Visitor.php(168): Mage_Core_Model_Abstract->save()
#9 /home/dme/public_html/app/code/core/Mage/Core/Model/App.php(1338): Mage_Log_Model_Visitor->initByRequest(Object(Varien_Event_Observer))
#10 /home/dme/public_html/app/code/core/Mage/Core/Model/App.php(1317): Mage_Core_Model_App->_callObserverMethod(Object(Mage_Log_Model_Visitor), 'initByRequest', Object(Varien_Event_Observer))
#11 /home/dme/public_html/app/Mage.php(448): Mage_Core_Model_App->dispatchEvent('controller_acti...', Array)
#12 /home/dme/public_html/app/code/core/Mage/Core/Controller/Varien/Action.php(527): Mage::dispatchEvent('controller_acti...', Array)
#13 /home/dme/public_html/app/code/core/Mage/Core/Controller/Front/Action.php(64): Mage_Core_Controller_Varien_Action->preDispatch()
#14 /home/dme/public_html/app/code/core/Mage/Core/Controller/Varien/Action.php(407): Mage_Core_Controller_Front_Action->preDispatch()
#15 /home/dme/public_html/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(250): Mage_Core_Controller_Varien_Action->dispatch('index')
#16 /home/dme/public_html/app/code/community/ArtsOnIT/OfflineMaintenance/Controller/Router/Standard.php(46): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#17 /home/dme/public_html/app/code/core/Mage/Core/Controller/Varien/Front.php(172): ArtsOnIT_OfflineMaintenance_Controller_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#18 /home/dme/public_html/app/code/core/Mage/Core/Model/App.php(354): Mage_Core_Controller_Varien_Front->dispatch()
#19 /home/dme/public_html/app/Mage.php(684): Mage_Core_Model_App->run(Array)
#20 /home/dme/public_html/index.php(89): Mage::run('', 'store')
#21 {main}";s:3:"url";s:1:"/";s:11:"script_name";s:10:"/index.php";s:4:"skin";s:7:"english";}