SQL查询替换文本列为超链接< a href ='';
我有一个表产品
ID | Productname | Product_url |
+----+-----------+--------------------------------------+
| 1 | ShirtXS | txthttps://www.product.com/shirt-xs |
| 2 | TrousersM | txthttps://www.trousers.org/tM-sizeM |
product_url是varchar(512)
如何编写SQL查询以将product_url列列文本值to < a href =“ productTextValue”> link</a>
?
基本上,来自product_url字段的所有值都应成为具有相同链接标签的链接。
https://www.product.com/shirt-xs to <a href="https://www.product.com/shirt-xs">Link</a>
https://www.trousers.org/tM-sizeM to <a href="https://www.trousers.org/tM-sizeM">Link</a>
ID | Productname | Poduct_url |
+----+-------------+--------------+
| 1 | ShirtXS | Link |
| 2 | TrousersM | Link |
I have a table Products
ID | Productname | Product_url |
+----+-----------+--------------------------------------+
| 1 | ShirtXS | txthttps://www.product.com/shirt-xs |
| 2 | TrousersM | txthttps://www.trousers.org/tM-sizeM |
Product_url is VARCHAR(512)
How to write SQL query to format Product_url column text value to <a href="producttextvalue">Link</a>
?
Basically, all values from Product_url field should become links with same link labels.
https://www.product.com/shirt-xs to <a href="https://www.product.com/shirt-xs">Link</a>
https://www.trousers.org/tM-sizeM to <a href="https://www.trousers.org/tM-sizeM">Link</a>
ID | Productname | Poduct_url |
+----+-------------+--------------+
| 1 | ShirtXS | Link |
| 2 | TrousersM | Link |
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
基本上,您可以使用
concat()
在URL周围添加所需的前缀和后缀,例如:正如我在评论中提到的那样,最好只保留数据库中的确切链接并格式化HTML您的前端页面中的代码。
Basically you can use
CONCAT()
to add needed prefix and suffix around the URL, like:However, as I mentioned in my comment, better to keep the exact link only in your database and to format the HTML code within your front-end page.