SQL查询替换文本列为超链接< a href ='';

发布于 2025-01-19 16:05:39 字数 827 浏览 3 评论 0原文

我有一个表产品

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

淡写薰衣草的香 2025-01-26 16:05:39

基本上,您可以使用concat()在URL周围添加所需的前缀和后缀,例如:

UPDATE
    `products`
SET
    `product_url` = CONCAT('<a href="', product_url, '">Link</a>');

正如我在评论中提到的那样,最好只保留数据库中的确切链接并格式化HTML您的前端页面中的代码。

Basically you can use CONCAT() to add needed prefix and suffix around the URL, like:

UPDATE
    `products`
SET
    `product_url` = CONCAT('<a href="', product_url, '">Link</a>');

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文