如何交换返回集中的行?(How to swap rows in a return set?)

在没有排序顺序列的表中,如何更改结果的顺序?

一个简单的示例表是:

id | content
1  | Some content here
2  | A page describing something
3  | Row 3 Content
...
7  | Some more content
8  | Row 8 Content
9  | An about-us page

执行简单的选择( SELECT * FROM table )将以默认顺序返回上述内容。

我现在要做的是更改结果,以便将id为3的行替换为id为8的行。

所以期望的输出是:

id | content
1  | Some content here
2  | A page describing something
8  | Row 8 Content
...
7  | Some more content
3  | Row 3 Content
9  | An about-us page

如何扩展我的选择查询以显示我想要的输出?


In a table without a sort-order column how do I change the order of the results?

A simple example table is:

id | content
1  | Some content here
2  | A page describing something
3  | Row 3 Content
...
7  | Some more content
8  | Row 8 Content
9  | An about-us page

Doing a simple select (SELECT * FROM table) will return the above in default order.

What I want to do now is change the results so that the row with id 3 is replaced with the row with the id of 8.

So the desired output is:

id | content
1  | Some content here
2  | A page describing something
8  | Row 8 Content
...
7  | Some more content
3  | Row 3 Content
9  | An about-us page

How do I extend my select query to show my desired output?


原文:https://stackoverflow.com/questions/33899516
2024-05-07 16:05

满意答案

如果没有get_field中的第二个参数,您需要处于循环中,而且似乎您不在。

如果您的代码位于页面顶部,则需要添加post ID参数,您需要使用global $post; 为拿到它,为实现它。

<?php
    global $post;

    $forside_slagord_stor = get_field('forside_slagord_stor', $post->ID);
    $forside_slagord_liten = get_field('forside_slagord_liten', $post->ID);
    $forside_slagord_liter = get_field('om_oss_tekst', $post->ID);
?>
<header>
<div class="container">
    <div class="intro-text">
        <div class="intro-lead-in"><?php echo $forside_slagord_stor;?></div>
        <div class="intro-heading"><?php echo $forside_slagord_liter;?></div>
        <a href="#services" class="page-scroll btn btn-xl">Tell Me More</a>
    </div>
</div>

关于你的一条评论的另一个答案:你不需要包含任何acf文件,当模板即将渲染时,所有插件文件和资产通常都会加载。

希望能帮助到你!


Without the second parameter in get_field, you need to be in the loop, and it's seems that you are not in.

If your code is at the top of the page, you need to add the post ID parameter, you need to use the global $post; to get it.

<?php
    global $post;

    $forside_slagord_stor = get_field('forside_slagord_stor', $post->ID);
    $forside_slagord_liten = get_field('forside_slagord_liten', $post->ID);
    $forside_slagord_liter = get_field('om_oss_tekst', $post->ID);
?>
<header>
<div class="container">
    <div class="intro-text">
        <div class="intro-lead-in"><?php echo $forside_slagord_stor;?></div>
        <div class="intro-heading"><?php echo $forside_slagord_liter;?></div>
        <a href="#services" class="page-scroll btn btn-xl">Tell Me More</a>
    </div>
</div>

Another answer about one of your comment : you don't need to include any file of acf, when the template is about to render, all the plugins files and assets are usually load.

Hope it helps!

相关问答

更多

着色ACF ggplot对象(Coloring ACF ggplot Object)

ggAcf函数基于autoplot.acf 。 您可以通过forecast:::autoplot.acf查看该函数。 当你这样做时,你会发现段和水平线的颜色在函数中是硬编码的,没有任何控制它们的选项。 要在不创建自己的新功能的情况下更改颜色,可以使用ggplot2中的函数在原始图上添加新图层。 但是,您需要使用与autoplot.acf相同的公式“手动”计算置信区间。 library(forecast) library(ggplot2) # Calculate confidence interv...

获取该值后的Wordpress ACF字段更新(Wordpress ACF field update after getting the value)

PHP add_action( 'admin_enqueue_scripts', 'portfolio_admin_script' ); function portfolio_admin_script() { global $post_type; if( 'portfolio' == $post_type ) wp_enqueue_script( 'portfolio-admin-script', get_stylesheet_directory_uri() . '...

如果ACF中继器子字段空白,如何隐藏(How to hide if ACF Repeater Sub_field Blank)

这里是魔术码: <?php if(get_field('field_name')): while(has_sub_field('field_name')): if(get_sub_field('subfield_name')): ?> <h2><?php echo get_sub_field('subfield_name'); ?></h2> <?php endif; endwhile; endif; here is the mag...

ACF Post Object返回false(ACF Post Object returns false)

对不起,我之前做过一个wp查询和后循环,并导致了某种冲突。 循环之后,我必须做wp_reset_postdata() Sorry about that, I had done a wp query and post loop before this and it was causing some sort of conflict. After the loop I had to do wp_reset_postdata()

Javascript getField返回0表示短划线/减号(Javascript getField returns 0 for a dash/minus symbol)

如果两个字段具有相同的属性,只需复制(复制/粘贴或重复拖动)它们即可。 具有相同名称的字段具有相同的值; 无需计算或其他脚本。 If the two fields have the same properties, simply duplicate (copy/paste or duplicate-drag) them. Fields with the same name have the same value; no calculation or other scripting needed.

.getField()返回空结果(.getField() returning empty result)

问题解决了。 问题实际上是使用Express指定的路线,与rethinkdb ! Problem solved. Issue was actually with my routes specified with Express and nothing to do with rethinkdb!

WordPress的:获取ACF子页面选项(Wordpress: Get ACF sub page options)

答案就在我眼前。 $context["options"] = get_fields("options"); 然后你可以用木材访问它 {{ options.FIELD_NAME }} 谢谢@Aibrean帮助我朝着正确的方向前进。 The answer was right before my eyes. $context["options"] = get_fields("options"); Then you can access it with Timber {{ options.FIELD...

FileMaker PHP API - getField()不返回所有值(FileMaker PHP API - getField() not returning all values)

你忘记检查你的fmphp webaccess帐户内的所有权限! 如果你像我一样忘记了这么简单的事情,记得去 File > Manage > Security > [Account] > "Edit the privilege set" you forgot to check all the privileges inside your fmphp webaccess account! If you're like me and forgot something as simple as this...

ACF - getfield()返回空值(ACF - getfield() returns blank value)

如果没有get_field中的第二个参数,您需要处于循环中,而且似乎您不在。 如果您的代码位于页面顶部,则需要添加post ID参数,您需要使用global $post; 为拿到它,为实现它。 <?php global $post; $forside_slagord_stor = get_field('forside_slagord_stor', $post->ID); $forside_slagord_liten = get_field('forside_slagord...

在一个图中绘制几个时间序列的acf(plot acf of several timeseries in one plot)

首先你看看str(ACF) : > str(ACF) List of 6 $ acf : num [1:26, 1:2, 1:2] 1 0.1451 0.1429 0.0291 0.124 ... $ type : chr "correlation" $ n.used: int 778 $ lag : num [1:26, 1:2, 1:2] 0 1 2 3 4 5 6 7 8 9 ... $ series: chr "test" $ snames: chr [1:2] "r...

相关文章

更多

Solr: a custom Search RequestHandler

As you know, I've been playing with Solr lately, tr ...

Becoming a data scientist

Data Week: Becoming a data scientist Data Pointed, ...

redis 字符串(String) SET 操作

命令格式: SET key value 把字符串值value存储到key中。如果存在此key,SE ...

7月最新发布11.2.0.1.2 Patch set update

7月13日,11g release 2 的第二个补丁集更新发布了;9i的最终版本为9.2.0.8,10 ...

How to set up Solr on Ubuntu 10.04 (or whatever)

How to set up Solr on Ubuntu 10.04 (or whatever) | ...

Python内建函数(A)

abs(x) 说明:abs(x)返回x的绝对值,如果参数是复数,则返回复数的模; 参数x:整 ...

[Hadoop] Error: JAVA_HOME is not set

在namenode启动脚本%Hadoop_HOME%/bin/start-dfs.sh的时候发现dat ...

[转]So You Want To Be A Producer

pro-du-cer n. 1. Someone from a game publisher who ...

最新问答

更多

获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)

我用Google搜索了一个解决方案。 “EnumDisplayModeProvider”是我自己设置网站的各种模式的枚举。 public EnumDisplayModeProvider GetDisplayModeId() { foreach (var mode in DisplayModeProvider.Instance.Modes) if (mode.CanHandleContext(HttpContext)) {

如何通过引用返回对象?(How is returning an object by reference possible?)

这相对简单:在类的构造函数中,您可以分配内存,例如使用new 。 如果你制作一个对象的副本,你不是每次都分配新的内存,而是只复制指向原始内存块的指针,同时递增一个也存储在内存中的引用计数器,使得每个副本都是对象可以访问它。 如果引用计数降至零,则销毁对象将减少引用计数并仅释放分配的内存。 您只需要一个自定义复制构造函数和赋值运算符。 这基本上是共享指针的工作方式。 This is relatively easy: In the class' constructor, you allocate m

矩阵如何存储在内存中?(How are matrices stored in memory?)

正如它在“熵编码”中所说的那样,使用Z字形图案,与RLE一起使用,在许多情况下,RLE已经减小了尺寸。 但是,据我所知,DCT本身并没有给出稀疏矩阵。 但它通常会增强矩阵的熵。 这是compressen变得有损的点:输入矩阵用DCT传输,然后量化量化然后使用霍夫曼编码。 As it says in "Entropy coding" a zig-zag pattern is used, together with RLE which will already reduce size for man

每个请求的Java新会话?(Java New Session For Each Request?)

你是如何进行重定向的? 您是否事先调用了HttpServletResponse.encodeRedirectURL()? 在这里阅读javadoc 您可以使用它像response.sendRedirect(response.encodeRedirectURL(path)); The issue was with the path in the JSESSIONID cookie. I still can't figure out why it was being set to the tomca

css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)

我认为word-break ,如果你想在一个单词中打破行,你可以指定它,这样做可以解决问题: .column { word-break:break-all; } jsFiddle演示。 您可以在此处阅读有关word-break属性的更多信息。 I think word-break, with which you can specify if you want to break line within a word, will do the trick: .column { word-break

无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)

我认为您忘记在分类时间内缩放输入图像,如train_test.prototxt文件的第11行所示。 您可能应该在C ++代码中的某个位置乘以该因子,或者使用Caffe图层来缩放输入(请查看ELTWISE或POWER图层)。 编辑: 在评论中进行了一次对话之后,结果发现在classification.cpp文件中错误地删除了图像均值,而在原始训练/测试管道中没有减去图像均值。 I think you have forgotten to scale the input image during cl

xcode语法颜色编码解释?(xcode syntax color coding explained?)

转到: Xcode => Preferences => Fonts & Colors 您将看到每个语法高亮颜色旁边都有一个简短的解释。 Go to: Xcode => Preferences => Fonts & Colors You'll see that each syntax highlighting colour has a brief explanation next to it.

在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)

你考虑过第三方拼写检查吗? 您可以将在C#中开发的自定义WinForms控件插入访问数据库吗? VB6控件怎么样? 如果你能找到一个使用第三方库进行拼写检查的控件,那可能会有效。 Have you considered a third party spell checker? Can you insert a custom WinForms controls developed in C# into an access database? What about a VB6 control? If

从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)

我有同样的问题,因为我在远程服务器上有两个图像,我需要在每天的预定义时间复制到我的本地服务器,这是我能够提出的代码... try { if(@copy('url/to/source/image.ext', 'local/absolute/path/on/server/' . date("d-m-Y") . ".gif")) { } else { $errors = error_get_last(); throw new Exception($err

从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))

我不确定我完全明白你在说什么。 你能编辑你的帖子并包含你正在做的Subversion命令/操作的特定顺序吗? 最好使用命令行svn客户端,以便容易为其他人重现问题。 如果您只是想获取文件的旧副本(即使该文件不再存在),您可以使用如下命令: svn copy ${repo}/trunk/moduleA/file1@${rev} ${repo}/trunk/moduleB/file1 其中${repo}是您的存储库的URL, ${rev}是您想要的文件的版本。 这将恢复该文件的旧版本,包括最高版本