How to order numbers in phrases? (MySQL)

71 Views Asked by At

i have a table where some iframes are listed. The problem is that they have different sizes. Now I want to order them by their size:

Here is a example: <iframe width="576" height="432" src="iframeadress" frameborder="0" allowfullscreen></iframe>

now i want to choose one of these numbers and order them by their size. I thought of a PHP-Site where I insert the number for the width as a variable.

But I don´t know how?

Or are there any other solutions? :)

I just find this one: Mysql order number / character combined but idk if its the right command :/

2

There are 2 best solutions below

2
On
SELECT * 
FROM TABLE
ORDER BY width 
0
On

In this case, you can use MySQL's ExtractValue() XML function, with a suitable XPath expression. For example:

ORDER BY ExtractValue(my_column, '//iframe/attribute::width')

However, you may wish to consider the suitability to your application of a schema comprising string columns that contain HTML fragments: perhaps columns containing various attributes, from which the HTML can be constructed in the presentation layer of your application, would be more appropriate?

More generally, the question posed in your title ("How to order numbers in phrases?") requires either a suitable parser (such as the above ExtractValue() function) or, if the phrases are in some regular language, a function that can extract matches by regular expression (e.g. lib_mysqludf_preg).