views:

97

answers:

3

Hi all,

I've got a little problem with exporting MySQL data to html. The problem is that in one field i have values like this: <a href="http://google.com"&gt;Google&lt;/a&gt; and when i export the table in html format the generated html table for this fields contains: &lt;a href=&quot;http://google.com&amp;quot;&amp;gt;Google&amp;lt;/a&amp;gt; which is not a valid html link. Is there way to export the table without mysql to convert the < and > chars?

im not using any code. i just use mysql command:mysql -H "select ...." and specify the output file.

Thanks!

A: 

The export purpose is to export data, not to offer a visual explanation of them. You'll have to go with php or any scripting language if you want to have valid link.

By the way, even if you can do it with tricks you should not.

Boris Guéry
A: 

Col. Shrapnel is correct. You need to do some changes in your code to accomplish your objective.

If you can provide some more information about your code then it will help to answer.

Krunal
the problem is that i'm not using any code i just use mysql command: mysql -H "select ...." and specify the output file.
countnazgul
+1  A: 
when i export the table in html format the generated html table for this fields contains:
&lt;a href=&quot;http://google.com&amp;quot;&amp;gt;Google&amp;lt;/a&amp;gt;

That's weird, I don't get that behaviour (in 5.1.34):

$ mysql -H -e "select 'a&b<c>d'";
<TABLE BORDER=1><TR><TH>a&b<c>d</TH></TR><TR><TD>a&b<c>d</TD></TR></TABLE>

And I want the behaviour you quote with the escaping! As you can see from my example, you run the risk of malformed HTML otherwise. eg. a </table> in a value would break the entire output.

If you want to control the output format to allow raw-HTML content in some or all columns, then (a) you will need to write some code to do this, and (b) you will have to be sure that the content in your database is known-safe HTML, free of malformed strings that might break the table, or malicious JavaScript.

The -H option to mysql is insufficient to the task, and seems quite unreliable judging by our different results! You'll want to pick a scripting language with MySQL bindings and output rows manually.

bobince