snipt

Ctrl+h for KB shortcuts

JavaScript

Get ID in js w/jQuery dom object return

$( document.getElementById("some_id") );
https://snipt.net/embed/a263aa5f5037f8d42f5005eb040cd348/
https://snipt.net/raw/a263aa5f5037f8d42f5005eb040cd348/
a263aa5f5037f8d42f5005eb040cd348
js
JavaScript
1
2016-09-24T02:38:11
True
False
False
Apr 08, 2014 at 09:22 AM
/api/public/snipt/107720/
get-id-in-js-wjquery-dom-object-return
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="nx">$</span><span class="p">(</span> <span class="nb">document</span><span class="p">.</span><span class="nx">getElementById</span><span class="p">(</span><span class="s2">&quot;some_id&quot;</span><span class="p">)</span> <span class="p">);</span> </span></pre></div> </td></tr></table>
element, get, id, jquery, js

PHP

PDO: Getting the Last Insert Id

1
2
3
4
<?php
$result = $db->exec("INSERT INTO table(firstname, lastname) VAULES('John', 'Doe')");
$insertId = $db->lastInsertId();
?>
https://snipt.net/embed/d8fb4a77d77c4ff3b0d01cce15aa3ce6/
https://snipt.net/raw/d8fb4a77d77c4ff3b0d01cce15aa3ce6/
d8fb4a77d77c4ff3b0d01cce15aa3ce6
php
PHP
4
2016-09-26T06:44:03
True
False
False
/api/public/snipt/53139/
pdo-getting-the-last-insert-id
<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></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="cp">&lt;?php</span> </span><span id="L-2"><a name="L-2"></a><span class="nv">$result</span> <span class="o">=</span> <span class="nv">$db</span><span class="o">-&gt;</span><span class="na">exec</span><span class="p">(</span><span class="s2">&quot;INSERT INTO table(firstname, lastname) VAULES(&#39;John&#39;, &#39;Doe&#39;)&quot;</span><span class="p">);</span> </span><span id="L-3"><a name="L-3"></a><span class="nv">$insertId</span> <span class="o">=</span> <span class="nv">$db</span><span class="o">-&gt;</span><span class="na">lastInsertId</span><span class="p">();</span> </span><span id="L-4"><a name="L-4"></a><span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
PDO, id, inserted, last

SQL

Change the id value

ALTER TABLE table AUTO_INCREMENT = 1000;
https://snipt.net/embed/c8b401be43ebdc3be671ef1688f14fd1/
https://snipt.net/raw/c8b401be43ebdc3be671ef1688f14fd1/
c8b401be43ebdc3be671ef1688f14fd1
sql
SQL
1
2016-09-21T20:12:35
True
False
False
Nov 19, 2012 at 07:12 AM
/api/public/snipt/50451/
change-the-id-value
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="k">ALTER</span> <span class="k">TABLE</span> <span class="k">table</span> <span class="n">AUTO_INCREMENT</span> <span class="o">=</span> <span class="mi">1000</span><span class="p">;</span> </span></pre></div> </td></tr></table>
"auto increment", id, sql

JavaScript

Get Timestamp and Date from Mongo ID

var timestamp = _id.toString().substring( 0, 8 );
var date = new Date( parseInt( timestamp, 16 ) * 1000 );
https://snipt.net/embed/dc5fb59a142040acdfe7da784540b72f/
https://snipt.net/raw/dc5fb59a142040acdfe7da784540b72f/
dc5fb59a142040acdfe7da784540b72f
js
JavaScript
2
2016-09-22T02:56:32
True
False
False
Oct 02, 2012 at 11:40 AM
/api/public/snipt/47925/
get-timestamp-and-date-from-mongo-id
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="kd">var</span> <span class="nx">timestamp</span> <span class="o">=</span> <span class="nx">_id</span><span class="p">.</span><span class="nx">toString</span><span class="p">().</span><span class="nx">substring</span><span class="p">(</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">8</span> <span class="p">);</span> </span><span id="L-2"><a name="L-2"></a><span class="kd">var</span> <span class="nx">date</span> <span class="o">=</span> <span class="k">new</span> <span class="nb">Date</span><span class="p">(</span> <span class="nb">parseInt</span><span class="p">(</span> <span class="nx">timestamp</span><span class="p">,</span> <span class="mi">16</span> <span class="p">)</span> <span class="o">*</span> <span class="mi">1000</span> <span class="p">);</span> </span></pre></div> </td></tr></table>
date, id, mongo, timestamp

PHP

Get post ID from Slug in WordPress

<?php $ID = url_to_postid(slug); ?>
https://snipt.net/embed/320dacfcc774b008d9430231f975308b/
https://snipt.net/raw/320dacfcc774b008d9430231f975308b/
320dacfcc774b008d9430231f975308b
php
PHP
1
2016-09-22T02:32:03
True
False
False
Aug 27, 2012 at 04:14 PM
/api/public/snipt/46352/
get-post-id-from-slug-in-wordpress
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="cp">&lt;?php</span> <span class="nv">$ID</span> <span class="o">=</span> <span class="nx">url_to_postid</span><span class="p">(</span><span class="nx">slug</span><span class="p">);</span> <span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
id, slug, wordpress

PHP

Pegar o id da ULR do YouTube

1
2
3
<?php
parse_str(parse_url($url_video_youtube, PHP_URL_QUERY), $parms_url_youtube);
$id_video_youtube = ($parms_url_youtube['v']) ? $parms_url_youtube['v'] : false;
https://snipt.net/embed/057070fda08f04752643e92a096ea4a4/
https://snipt.net/raw/057070fda08f04752643e92a096ea4a4/
057070fda08f04752643e92a096ea4a4
php
PHP
3
2016-09-26T06:16:55
True
False
False
Jul 18, 2012 at 08:50 AM
/api/public/snipt/44073/
pegar-o-id-da-ulr-do-youtube
<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></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="cp">&lt;?php</span> </span><span id="L-2"><a name="L-2"></a><span class="nb">parse_str</span><span class="p">(</span><span class="nb">parse_url</span><span class="p">(</span><span class="nv">$url_video_youtube</span><span class="p">,</span> <span class="nx">PHP_URL_QUERY</span><span class="p">),</span> <span class="nv">$parms_url_youtube</span><span class="p">);</span> </span><span id="L-3"><a name="L-3"></a><span class="nv">$id_video_youtube</span> <span class="o">=</span> <span class="p">(</span><span class="nv">$parms_url_youtube</span><span class="p">[</span><span class="s1">&#39;v&#39;</span><span class="p">])</span> <span class="o">?</span> <span class="nv">$parms_url_youtube</span><span class="p">[</span><span class="s1">&#39;v&#39;</span><span class="p">]</span> <span class="o">:</span> <span class="k">false</span><span class="p">;</span> </span></pre></div> </td></tr></table>
id, php, youtube

PHP

Normalize the title for use as a <div> id

<?=preg_replace("![^a-z0-9]+!i", "-",get_the_title()); ?>
https://snipt.net/embed/87b3b5fe4257739a817c88abbc6889a8/
https://snipt.net/raw/87b3b5fe4257739a817c88abbc6889a8/
87b3b5fe4257739a817c88abbc6889a8
php
PHP
1
2016-09-26T02:58:02
True
False
False
/api/public/snipt/39810/
normalize-the-title-for-use-as-a-div-id
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="cp">&lt;?</span><span class="o">=</span><span class="nb">preg_replace</span><span class="p">(</span><span class="s2">&quot;![^a-z0-9]+!i&quot;</span><span class="p">,</span> <span class="s2">&quot;-&quot;</span><span class="p">,</span><span class="nx">get_the_title</span><span class="p">());</span> <span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
id, title, wordpress

JavaScript

Set $ to ID

var $ = function (id) { return document.getElementById(id); }
https://snipt.net/embed/b80ef64d01b21917fa801664371b929b/
https://snipt.net/raw/b80ef64d01b21917fa801664371b929b/
b80ef64d01b21917fa801664371b929b
js
JavaScript
1
2016-09-25T16:58:22
True
False
False
/api/public/snipt/37474/
set-to-id
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="kd">var</span> <span class="nx">$</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">id</span><span class="p">)</span> <span class="p">{</span> <span class="k">return</span> <span class="nb">document</span><span class="p">.</span><span class="nx">getElementById</span><span class="p">(</span><span class="nx">id</span><span class="p">);</span> <span class="p">}</span> </span></pre></div> </td></tr></table>
$, id, var

SQL

Id duplicado em tabelas

1
2
3
4
5
SELECT ZD2_DOMCOD, COUNT(*)
FROM ZD2010 
WHERE D_E_L_E_T_ != '*'
GROUP BY ZD2_DOMCOD
HAVING COUNT(*) > 1
https://snipt.net/embed/7f49c369f2b8ddc4f4e3e0fb1fbe8492/
https://snipt.net/raw/7f49c369f2b8ddc4f4e3e0fb1fbe8492/
7f49c369f2b8ddc4f4e3e0fb1fbe8492
sql
SQL
5
2016-09-25T03:51:40
True
False
False
/api/public/snipt/24988/
id-duplicado-em-tabelas
<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 id="L-1"><a name="L-1"></a><span class="k">SELECT</span> <span class="n">ZD2_DOMCOD</span><span class="p">,</span> <span class="k">COUNT</span><span class="p">(</span><span class="o">*</span><span class="p">)</span> </span><span id="L-2"><a name="L-2"></a><span class="k">FROM</span> <span class="n">ZD2010</span> </span><span id="L-3"><a name="L-3"></a><span class="k">WHERE</span> <span class="n">D_E_L_E_T_</span> <span class="o">!=</span> <span class="s1">&#39;*&#39;</span> </span><span id="L-4"><a name="L-4"></a><span class="k">GROUP</span> <span class="k">BY</span> <span class="n">ZD2_DOMCOD</span> </span><span id="L-5"><a name="L-5"></a><span class="k">HAVING</span> <span class="k">COUNT</span><span class="p">(</span><span class="o">*</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">1</span> </span></pre></div> </td></tr></table>
duplicado, id, sql
Copyrighted, illegal, or inappropriate content? Email support@snipt.net.