Display correct characters when Select on column containing HTML - html

In my database I store some html code (from CKEditor), and I would like to be able to check these values in PhpMyAdmin.
There is one small problem : the HTML is written in french so there are a lot ar &eacute: or other kind of html characters that make the values hard to read.
I know there are settings to avoid CKEditor replacing the characters with &eacute:, but I do not want to change anything in the code or configuration tight now.
Is there any MySQL command that would allow to display the text correctly?
Note : doing a str_replace or kind is not wanted.
Edit :
For exemple for an element stored as follow :
<div>
&eacute:l&eacute:phant
</div>
I would like to read in my result column :
<div>
éléphant
</div>

I'm afraid there is no way to do directly what you are asking for.
The best way I've found would be to create a function which decodes the text, and then use it in select statements:
mysql> SELECT HTML_UnEncode('Dr.Hübner');
+---------------------------------+
| HTML_UnEncode('Dr.Hübner') |
+---------------------------------+
| Dr.Hübner |
+---------------------------------+
Here is the link to that function:
http://forums.mysql.com/read.php?98,246527,246527

This is easily accomplished with phpMyAdmin's transformation feature.
My answer assumes you already have a properly configured phpMyAdmin Configuration Storage, if not you just have to create the tables by editing the file in examples/create_tables.sql to set a username, database name, and password, then import that to your MySQL server. Edit config.inc.php to add the directives you can find listed beginning at http://docs.phpmyadmin.net/en/latest/config.html#cfg_Servers_pmadb .
Before:
Anyway, edit your table by going to the Structure tab.
Click the pencil icon/Change link for the column(s) containing the HTML entities.
On the resulting page, look for the "Browser display transformation" dropdown. One of the built in transformations is exactly what you're after: "Text/Plain: Formatted"
Click Save, then you can Browse the table and should see the transformed output.
After:

Related

Render Emoji HTML Entity stored in database in Django?

I've stored the following HTML Entity (🌶🌶) in varchar and is calling it from the database. And then using a for block in the HTML.
However, when the page is rendered, it is displayed as &#x1f336; instead of the red pepper, I was hoping for.
Am wondering how the amp; got inserted.
Want 🌶 but got &#x1f336;
Try marking the output as |safe.
Only do this if the database code is something you control and you know it is actually safe.
Read me here from the Django Docs: https://docs.djangoproject.com/en/3.0/ref/templates/builtins/#std:templatefilter-safe

Replacing some URLs with another

I have a MySQL 5.7.29 database on which a website is built. I need to construct a query to find all table rows containing lines such as
https://example.com/index.php?topic=7989.0
or similar and replace them with
https://example.com/my-redirect-page/?7989.0
The wildcard here is the ?topic=7989.0 as this can be something like ?topic=1234 or even ?topic=3456.0#anchor
I can display the rows they appear in (in PHPMyAdmin) using this (thanks to 'sticky bit' below) :
SELECT * FROM `abc_posts` WHERE `post_content` LIKE '%example.com\index.php?topic%'
My problem is that I then need to change just that URL when there is also text content around it.
Thanks in advance.
The question mark doesn't need to be escaped.
But 'https://example.com/index.php?topic=7989.0' isn't LIKE '%example.com\?topic%' as the question mark doesn't immediately follow the host name.
Try:
...
post_content LIKE '%example.com/index.php?topic%'
...
You could do something like thin to find them
SELECT 'https://example.com/index.php?topic=7989.0'
WHERE 'https://example.com/index.php?topic=7989.0' REGEXP 'example.com/index.php?topic=';
Which would find all rows. But for replacing it, you must also tell which database version youh have mysql 5.x have not many regex fucntions mariadb and mysql 8 have much more

Shorttext data type uses wrong character cut-off

I have a table with one field that is made up of hyperlinks such as this:
<http://nl.dbpedia.org/resource/Wereldkampioenschappen_indooratletiek_2008>
Now I have to change the datatype of this field to shorttext so I can later use JOIN in the query. From what I understand it is supposed to automatically cut-off all lines that go above the 255 character threshold. This is not the case with the example above, however if I change the datatype to ShortText it changes that text to:
<http://nl.dbpedia.org/resource/Wereldkampioenschappen_in
So it seems to keep only 57 characters instead of 255. I also tried using the Import Text Wizard and putting the datatype as ShortText there (so it never gets imported as a hyperlink), but the same problem persists as when I change it from hyperlink to shorttext.
Does anyone know how I can fix this? Thanks :)
P.S. I literally started working with Access today, so I'm still very much Googling everything. I couldn't find this problem anywhere though unfortunately.
Short Text will truncate the text to the number of characters specified in the "Table Design" view. You can specify any number of characters from 1 to 255.
More Information:
YouTube : Access 2016: Getting Started
Office.com : Access Database design basics
Office.com : Introduction to data types and field properties
Office.com : Data types for Access desktop databases
I imported using fixed width instead of delimited. Use delimited and this problem goes away!

MySQL find and replace XXX if it's between YYY and ZZZ

I'm working on a WordPress-based project and I need to batch edit the posts from the database.
At the moment I have cells, where the content is Text <pre> Text\r\nText\r\nText </pre>
What I need to do is find all the \r\n strings and replace them with \r\n\r\n. So far I have this:
UPDATE `table_name`
SET `field_name` = replace(field_name, '\r\n', '\r\n\r\n\')
The issue is, there is also \r\n\ text outside the <pre> tags, which I don't want to affect. That's why I need to do something like find (start: '<pre>' end: '</pre>') before calling the replace. I just have no idea how to do this in MySQL.
When web searching, I found some stuff about regex but I have no idea how that works.
MySQL doesn't have the regexp replace functionality. I'd say you have two options - either create an user defined function that will do this kind of replacement, or, if you can't / don't know how to, you have to use a script/program written in a different language. It may be e.g. a PHP script that will connect to the db and do the desired replacement. Another way would be to dump the table containing your posts to a file, use sed or something similar and import the data once again.
Using sed would probably take less time than PHP and the syntax is fairly easy to learn.
Whatever you choose remember it's always a good idea to make a backup before.

Why would error say Column 'n' does not belong to table when it clearly does?

I am running a Query from ASP.NET on a Microsoft Access database. The error states: Column 'Area1' does not belong to table.
It looks like the error occurs here:
cmd.Parameters.AddWithValue("#" + columnName, progressRow[columnName]);
The sql command looks like this:
Extract.exe Warning: 0 : 03/09/2014 10:48:28 | CSUtilities | serengeti | Add Query : INSERT INTO Property (Address1,Address2,Address3,Address4,Area1,Area10,Area11,Area12,Area13,Area14,Area15,Area16,Area17,Area18,Area19,Area2,Area20,Area3,Area4,Area5,Area6,Area7,Area8,Area9,BlockFlag,CapitalValue,ConstructionYear,CurrentStock,Department,DepartmentFIS,DisposalDate,DisposalReason,DoubleBeds,DwellingType,DwellingTypeCode,EastingGridRef,ElevationGridRef,HeatingCode,HouseNumber,KeyBlockProperty,KeyCurrTcyId,KeyProperty,KeyPropertyTypeCode,KeyStreet,LocalPerm,NorthingGridRef,OwningDepartment,Postcode,PropertyClassCode,PropertyGroup,QLX,RepairResponsibility,RiskLevel,RTBCode,SingleBeds,StatPerm,Suffix,Telephone,TenureCode,UserCode,Void,WardCode,WaterCode, UpdateFlag) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
Area1 is clearly defined in the Design View as a Short Text field.
I ran the following test manually and it works:
INSERT INTO Property (Address1,Address2,Address3,Address4,Area1) VALUES ('Test1','Test','Test','Test','Test')
What is it playing at?
It MIGHT be getting confused with the named parameters being the same as that of the column names (I've seen it before, but cant remember which engine). Try changing your function of add parameters with value to "#x" + column name... this way the OleDb driver won't be trying to look for a column Area1 to match with #Area1, but look for #xArea1 (and likewise for the rest).
One OTHER possibility is the data you are inserting too. Might there be something with special characters like an "#" or "?" or similar in such fields that are confusing the post?