Snipt.net is closing on December 31st, 2016

For more information, please visit this blog post.

snipt

Ctrl+h for KB shortcuts

PHP

Avoid duplicate content in WP

1
2
3
4
5
6
7
8
<!-- Paste these lines in the head -->

<?php if((is_home() && ($paged < 2 )) || is_single() || is_page() || is_category()){
    echo '<meta name="robots" content="index,follow" />';
} else {
    echo '<meta name="robots" content="noindex,follow" />';
}
?>
https://snipt.net/embed/afb90343eb9e1633d4f5b769fd5e5374/
https://snipt.net/raw/afb90343eb9e1633d4f5b769fd5e5374/
afb90343eb9e1633d4f5b769fd5e5374
php
PHP
8
2016-12-10T01:23:16
True
False
False
Aug 01, 2012 at 02:12 PM
/api/public/snipt/44894/
avoid-duplicate-content-in-wp
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a> <a href="#L-7">7</a> <a href="#L-8">8</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="x">&lt;!-- Paste these lines in the head --&gt;</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a><span class="cp">&lt;?php</span> <span class="k">if</span><span class="p">((</span><span class="nx">is_home</span><span class="p">()</span> <span class="o">&amp;&amp;</span> <span class="p">(</span><span class="nv">$paged</span> <span class="o">&lt;</span> <span class="mi">2</span> <span class="p">))</span> <span class="o">||</span> <span class="nx">is_single</span><span class="p">()</span> <span class="o">||</span> <span class="nx">is_page</span><span class="p">()</span> <span class="o">||</span> <span class="nx">is_category</span><span class="p">()){</span> </span><span id="L-4"><a name="L-4"></a> <span class="k">echo</span> <span class="s1">&#39;&lt;meta name=&quot;robots&quot; content=&quot;index,follow&quot; /&gt;&#39;</span><span class="p">;</span> </span><span id="L-5"><a name="L-5"></a><span class="p">}</span> <span class="k">else</span> <span class="p">{</span> </span><span id="L-6"><a name="L-6"></a> <span class="k">echo</span> <span class="s1">&#39;&lt;meta name=&quot;robots&quot; content=&quot;noindex,follow&quot; /&gt;&#39;</span><span class="p">;</span> </span><span id="L-7"><a name="L-7"></a><span class="p">}</span> </span><span id="L-8"><a name="L-8"></a><span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
duplicate, wp

MySQL

Insert record, if exists just update

1
2
3
4
5
INSERT INTO `accounts` (`nickname`,`type`)
VALUES ('beat',0)
ON DUPLICATE KEY UPDATE
`type` = 0
//nickname must be unique index
https://snipt.net/embed/8e474487bc343632a3c0dc42b2bca791/
https://snipt.net/raw/8e474487bc343632a3c0dc42b2bca791/
8e474487bc343632a3c0dc42b2bca791
mysql
MySQL
5
2016-12-06T21:14:46
True
False
False
/api/public/snipt/31289/
insert-record-if-exists-just-update
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="k">INSERT</span> <span class="k">INTO</span> <span class="ss">`accounts`</span> <span class="p">(</span><span class="ss">`nickname`</span><span class="p">,</span><span class="ss">`type`</span><span class="p">)</span> </span><span id="L-2"><a name="L-2"></a><span class="k">VALUES</span> <span class="p">(</span><span class="s1">&#39;beat&#39;</span><span class="p">,</span><span class="mi">0</span><span class="p">)</span> </span><span id="L-3"><a name="L-3"></a><span class="k">ON</span> <span class="n">DUPLICATE</span> <span class="k">KEY</span> <span class="k">UPDATE</span> </span><span id="L-4"><a name="L-4"></a><span class="ss">`type`</span> <span class="o">=</span> <span class="mi">0</span> </span><span id="L-5"><a name="L-5"></a><span class="o">//</span><span class="n">nickname</span> <span class="n">must</span> <span class="n">be</span> <span class="k">unique</span> <span class="k">index</span> </span></pre></div> </td></tr></table>
duplicate, mysql

MySQL

Look for duplicate rows, in the same table, by a different column (not primary or unique).

1
2
3
4
5
SELECT p1.id,p1.cod , p2.id,p2.cod #here we find the duplicate data from cod column, but i need the ID to show ...
FROM `st_produse` p1 #the table, first time 
LEFT JOIN st_produse p2 ON p1.cod = p2.cod #the table second time
WHERE p1.id <> p2.id #here put the key or a unique column
GROUP BY p1.cod #the column in case, first time
https://snipt.net/embed/bf3c02664861ae205e67413afd426477/
https://snipt.net/raw/bf3c02664861ae205e67413afd426477/
bf3c02664861ae205e67413afd426477
mysql
MySQL
5
2016-12-07T12:04:10
True
False
False
/api/public/snipt/26852/
look-for-duplicate-rows-in-the-same-table-by-a-different-column-not-primary-or-unique
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="k">SELECT</span> <span class="n">p1</span><span class="p">.</span><span class="n">id</span><span class="p">,</span><span class="n">p1</span><span class="p">.</span><span class="n">cod</span> <span class="p">,</span> <span class="n">p2</span><span class="p">.</span><span class="n">id</span><span class="p">,</span><span class="n">p2</span><span class="p">.</span><span class="n">cod</span> <span class="c1">#here we find the duplicate data from cod column, but i need the ID to show ...</span> </span><span id="L-2"><a name="L-2"></a><span class="k">FROM</span> <span class="ss">`st_produse`</span> <span class="n">p1</span> <span class="c1">#the table, first time </span> </span><span id="L-3"><a name="L-3"></a><span class="k">LEFT</span> <span class="k">JOIN</span> <span class="n">st_produse</span> <span class="n">p2</span> <span class="k">ON</span> <span class="n">p1</span><span class="p">.</span><span class="n">cod</span> <span class="o">=</span> <span class="n">p2</span><span class="p">.</span><span class="n">cod</span> <span class="c1">#the table second time</span> </span><span id="L-4"><a name="L-4"></a><span class="k">WHERE</span> <span class="n">p1</span><span class="p">.</span><span class="n">id</span> <span class="o">&lt;&gt;</span> <span class="n">p2</span><span class="p">.</span><span class="n">id</span> <span class="c1">#here put the key or a unique column</span> </span><span id="L-5"><a name="L-5"></a><span class="k">GROUP</span> <span class="k">BY</span> <span class="n">p1</span><span class="p">.</span><span class="n">cod</span> <span class="c1">#the column in case, first time</span> </span></pre></div> </td></tr></table>
duplicate, mysql, select
Copyrighted, illegal, or inappropriate content? Email [email protected].