Posts tagged with 'mysql'

Combining bordering ranges of data in MySQL


( ! ) Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseStartTag: invalid element name in Entity, line: 58 in /var/www/ciaranmcnulty.com/application/models/Post.php on line 25
Call Stack
#TimeMemoryFunctionLocation
10.000266624{main}( )../index.php:0
20.03532985204Zend_Controller_Front->dispatch( )../index.php:47
30.04193466604Zend_Controller_Dispatcher_Standard->dispatch( )../Front.php:946
40.32088156472Zend_Controller_Action->dispatch( )../Standard.php:293
50.32108156608BlogController->tagAction( )../Action.php:502
60.33128167288Zend_Controller_Action->render( )../BlogController.php:204
70.33138167288Zend_Controller_Action_Helper_ViewRenderer->render( )../Action.php:207
80.33198167288Zend_Controller_Action_Helper_ViewRenderer->renderScript( )../ViewRenderer.php:942
90.33198167288Zend_View_Abstract->render( )../ViewRenderer.php:921
100.33208208556Zend_View->_run( )../Abstract.php:787
110.33238224720include( '/var/www/ciaranmcnulty.com/application/views/scripts/blog/list.phtml' )../View.php:107
120.33258224720Post->getSummary( )../list.phtml:13
130.33268224720DOMDocument->loadHTML( )../Post.php:25

( ! ) Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseStartTag: invalid element name in Entity, line: 83 in /var/www/ciaranmcnulty.com/application/models/Post.php on line 25
Call Stack
#TimeMemoryFunctionLocation
10.000266624{main}( )../index.php:0
20.03532985204Zend_Controller_Front->dispatch( )../index.php:47
30.04193466604Zend_Controller_Dispatcher_Standard->dispatch( )../Front.php:946
40.32088156472Zend_Controller_Action->dispatch( )../Standard.php:293
50.32108156608BlogController->tagAction( )../Action.php:502
60.33128167288Zend_Controller_Action->render( )../BlogController.php:204
70.33138167288Zend_Controller_Action_Helper_ViewRenderer->render( )../Action.php:207
80.33198167288Zend_Controller_Action_Helper_ViewRenderer->renderScript( )../ViewRenderer.php:942
90.33198167288Zend_View_Abstract->render( )../ViewRenderer.php:921
100.33208208556Zend_View->_run( )../Abstract.php:787
110.33238224720include( '/var/www/ciaranmcnulty.com/application/views/scripts/blog/list.phtml' )../View.php:107
120.33258224720Post->getSummary( )../list.phtml:13
130.33268224720DOMDocument->loadHTML( )../Post.php:25

( ! ) Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseStartTag: invalid element name in Entity, line: 113 in /var/www/ciaranmcnulty.com/application/models/Post.php on line 25
Call Stack
#TimeMemoryFunctionLocation
10.000266624{main}( )../index.php:0
20.03532985204Zend_Controller_Front->dispatch( )../index.php:47
30.04193466604Zend_Controller_Dispatcher_Standard->dispatch( )../Front.php:946
40.32088156472Zend_Controller_Action->dispatch( )../Standard.php:293
50.32108156608BlogController->tagAction( )../Action.php:502
60.33128167288Zend_Controller_Action->render( )../BlogController.php:204
70.33138167288Zend_Controller_Action_Helper_ViewRenderer->render( )../Action.php:207
80.33198167288Zend_Controller_Action_Helper_ViewRenderer->renderScript( )../ViewRenderer.php:942
90.33198167288Zend_View_Abstract->render( )../ViewRenderer.php:921
100.33208208556Zend_View->_run( )../Abstract.php:787
110.33238224720include( '/var/www/ciaranmcnulty.com/application/views/scripts/blog/list.phtml' )../View.php:107
120.33258224720Post->getSummary( )../list.phtml:13
130.33268224720DOMDocument->loadHTML( )../Post.php:25

( ! ) Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseStartTag: invalid element name in Entity, line: 121 in /var/www/ciaranmcnulty.com/application/models/Post.php on line 25
Call Stack
#TimeMemoryFunctionLocation
10.000266624{main}( )../index.php:0
20.03532985204Zend_Controller_Front->dispatch( )../index.php:47
30.04193466604Zend_Controller_Dispatcher_Standard->dispatch( )../Front.php:946
40.32088156472Zend_Controller_Action->dispatch( )../Standard.php:293
50.32108156608BlogController->tagAction( )../Action.php:502
60.33128167288Zend_Controller_Action->render( )../BlogController.php:204
70.33138167288Zend_Controller_Action_Helper_ViewRenderer->render( )../Action.php:207
80.33198167288Zend_Controller_Action_Helper_ViewRenderer->renderScript( )../ViewRenderer.php:942
90.33198167288Zend_View_Abstract->render( )../ViewRenderer.php:921
100.33208208556Zend_View->_run( )../Abstract.php:787
110.33238224720include( '/var/www/ciaranmcnulty.com/application/views/scripts/blog/list.phtml' )../View.php:107
120.33258224720Post->getSummary( )../list.phtml:13
130.33268224720DOMDocument->loadHTML( )../Post.php:25

( ! ) Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseStartTag: invalid element name in Entity, line: 154 in /var/www/ciaranmcnulty.com/application/models/Post.php on line 25
Call Stack
#TimeMemoryFunctionLocation
10.000266624{main}( )../index.php:0
20.03532985204Zend_Controller_Front->dispatch( )../index.php:47
30.04193466604Zend_Controller_Dispatcher_Standard->dispatch( )../Front.php:946
40.32088156472Zend_Controller_Action->dispatch( )../Standard.php:293
50.32108156608BlogController->tagAction( )../Action.php:502
60.33128167288Zend_Controller_Action->render( )../BlogController.php:204
70.33138167288Zend_Controller_Action_Helper_ViewRenderer->render( )../Action.php:207
80.33198167288Zend_Controller_Action_Helper_ViewRenderer->renderScript( )../ViewRenderer.php:942
90.33198167288Zend_View_Abstract->render( )../ViewRenderer.php:921
100.33208208556Zend_View->_run( )../Abstract.php:787
110.33238224720include( '/var/www/ciaranmcnulty.com/application/views/scripts/blog/list.phtml' )../View.php:107
120.33258224720Post->getSummary( )../list.phtml:13
130.33268224720DOMDocument->loadHTML( )../Post.php:25

( ! ) Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseStartTag: invalid element name in Entity, line: 162 in /var/www/ciaranmcnulty.com/application/models/Post.php on line 25
Call Stack
#TimeMemoryFunctionLocation
10.000266624{main}( )../index.php:0
20.03532985204Zend_Controller_Front->dispatch( )../index.php:47
30.04193466604Zend_Controller_Dispatcher_Standard->dispatch( )../Front.php:946
40.32088156472Zend_Controller_Action->dispatch( )../Standard.php:293
50.32108156608BlogController->tagAction( )../Action.php:502
60.33128167288Zend_Controller_Action->render( )../BlogController.php:204
70.33138167288Zend_Controller_Action_Helper_ViewRenderer->render( )../Action.php:207
80.33198167288Zend_Controller_Action_Helper_ViewRenderer->renderScript( )../ViewRenderer.php:942
90.33198167288Zend_View_Abstract->render( )../ViewRenderer.php:921
100.33208208556Zend_View->_run( )../Abstract.php:787
110.33238224720include( '/var/www/ciaranmcnulty.com/application/views/scripts/blog/list.phtml' )../View.php:107
120.33258224720Post->getSummary( )../list.phtml:13
130.33268224720DOMDocument->loadHTML( )../Post.php:25

A while back, a friend of mine was working on a database that contained bookings for some equipment, and he needed to separate it out into blocks representing when it was free and busy, regardless of whether the busy times were bookings by the same people or not.

Just today, a different friend who works with mobile phones was dealing with a table that contained IP ranges and which network operator owned them. He commented that he suspected a lot of the ranges overlapped or adjoined each other, and could be combined together into larger blocks.

Both of these problems are ones of finding contiguous (or, bordering) ranges inside data.

It's tempting to try and approach the problem in an iterative way - find a block, try and find blocks border it, and work outwards from there but it's possible to solve this sort of thing in a non-iterative way with a single SQL query, which is what I'd like to show you how to do using MySQL.