将第一段内容交换为最后一段(Swap first paragraph of content to be the last one)

编程入门 行业动态 更新时间:2024-10-22 18:29:01
将第一段内容交换为最后一段(Swap first paragraph of content to be the last one)

当我跑

SELECT * FROM `content` where article_id=123

我得到了结果

<p>{sometag}some things{/sometag}</p> <p>some content</p> <p>some more content</p>

我需要修改该结果才能获得:

<p>some content</p> <p>some more content</p> <p>{sometag}some things{/sometag}</p>

注意:第一段移到最后。

我必须通过phpMyAdmin做到这一点,但我也可以使用PHP。 在PHP我知道如何连接到数据库,加载和更新内容,但我不知道如何切换段落? 需要帮助。

When i run

SELECT * FROM `content` where article_id=123

I get result

<p>{sometag}some things{/sometag}</p> <p>some content</p> <p>some more content</p>

I need to do modification of that result in order to get:

<p>some content</p> <p>some more content</p> <p>{sometag}some things{/sometag}</p>

Note: that first paragraph is moved to the end.

I have to do that over phpMyAdmin, but I can also use PHP. In PHP i know how to conenct to database, load and update content, but i dont know how to switch paragraph? Need help on that.

最满意答案

我不得不在这里做出很多假设,因为你还没有真正写过问题,甚至没有提供任何信息。

你说“列的内容”所以我假设你将这3个HTML段落标记存储在某个数据库的某个列中,并且你想要改变它们返回的顺序。

您想要的顺序不是字母顺序,因此您无法通过存储的值对它们进行排序。 您应该创建一个新列并订购,例如创建一个名为“manual_order”的列,然后:

SELECT * FROM table ORDER BY manual_order

编辑

您对帖子的更新清楚地说明了您要做的事情 - 当您“知道”您的意思时,它总是更容易,但并不总是让所有人都清楚!

除非您提供ORDER BY子句,否则无法依赖从MySQL返回的结果的顺序。

SELECT * FROM table

如果您没有对该表进行任何DELETE / UPDATE或REPLACE,则将以插入顺序返回。

如果您正在使用INNODB表执行SELECT * FROM表,它们将由PRIMARY KEY顺序而不是INSERT顺序返回。

如果要更改顺序,则必须提供ORDER BY子句。 如果您想要一个在数字方面没有意义的订单,那么按照建议最好创建另一个列,您可以在其中指定订单并在ORDER BY子句中使用该订单。

如果您正在使用INNODB并想要反向查询的内容,您可以使用:

SELECT * FROM table ORDER BY primarykey DESC

I’m forced to make a lot of assumptions here as you haven’t really written a question or even provided any information.

You say “content of a column” so I will assume you have those 3 HTML paragraph tags stored in a column of a database somewhere and you want to change the order they are returned.

The order you want isn't alphabetic so you can’t order them by the stored values. You should create a new column and order that, for example create a column named “manual_order” and then:

SELECT * FROM table ORDER BY manual_order

Edit

Your update to your post makes it clear what you're trying to do - it's always easier when 'you' know what you mean but not always clear to everyone else!

The order of the results returned from MySQL cannot be relied upon unless you are supplying an ORDER BY clause.

SELECT * FROM table

Will return then in insert order providing you haven't had any DELETE / UPDATE or REPLACE to that table.

If you're doing SELECT * FROM table with an INNODB table they will be returned by PRIMARY KEY order and not INSERT order.

If you want to change the order you must supply an ORDER BY clause. If you want an order that doesn't make sense in numeric terms then as suggested it would be best to create another column where you can specify the order and use that in the ORDER BY clause.

If you're using INNODB and wanting a reverse of what has been queried you could just use:

SELECT * FROM table ORDER BY primarykey DESC

更多推荐

本文发布于:2023-07-06 07:58:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1047594.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:内容   Swap   content   paragraph

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!