SELECT c.*, p1.*
FROM customer c
JOIN purchase p1 ON (c.id = p1.customer_id)
LEFT OUTER JOIN purchase p2 ON (c.id = p2.customer_id AND
(p1.date < p2.date OR p1.date = p2.date AND p1.id < p2.id))
WHERE p2.id IS NULL;
source: http://stackoverflow.com/questions/2111384/sql-join-selecting-the-last-records-in-a-one-to-many-relationship2015 m. rugsėjo 26 d., šeštadienis
SQL join`inimas po vieną naujausią eulutę
jQuery perdavima x-auth-token
$.ajax({
url : myurl,
headers: {
'X-Auth-Token' : token
});
PHP / ajax apsauga, su kintamu raktu ir laiko žyma
$time = time();
$hash = md5($key . $time);
$url = "http://domain.com/iframe?hash=$hash&time=$time";
On the other side you should first check if the timestamp is in the limits (e.g. not older than five minutes) and than rehash with the key and the submitted timestamp. If you get the same hash the request is valid.
2015 m. rugsėjo 24 d., ketvirtadienis
Unikalūs SEO URL / SLUG
tarkime, jūs formuojate straipsnių URL iš straipsnių antraščių. Kyla poreikis išvengti vienodų URL jei bus du tokie pat straipsniai, pvz.: 'test-slug-1', 'test-slug-2' and 'test-slug-3'
Tam pagelbės funkcija
Tam pagelbės funkcija
$slug = preg_replace("/-$/","",preg_replace('/[^a-z0-9]+/i', "-", strtolower($title)));
Just hit the database once, grab everything at once, chances are that's the biggest bottleneck.
$query = "SELECT * FROM $table_name WHERE $field_name LIKE '".$slug."%'";
Then put your results in an array (let's say
$slugs
)//we only bother doing this if there is a conflicting slug already
if(mysqli_num_rows($result) !== 0 && in_array($slug, $slugs)){
$max = 0;
//keep incrementing $max until a space is found
while(in_array( ($slug . '-' . ++$max ), $slugs) );
//update $slug with the appendage
$slug .= '-' . $max;
}
We use the
in_array()
checks as if the slug was my-slug
the LIKE
would also return rows such asmy-slug-is-awesome
my-slug-is-awesome-1
my-slug-rules
šaltinis: http://stackoverflow.com/questions/15971685/creating-unique-page-title-slugs-php
2015 m. rugsėjo 21 d., pirmadienis
Mobile app per Web-View
Jei reikia sukurti appsą, nesunkiai galima integruoti į appsą web-appą, veikiantį serveryje, pasinaudojant WEB-VIEW: https://developer.chrome.com/multidevice/webview/gettingstarted ir
http://stackoverflow.com/questions/14670638/webview-load-website-when-online-load-local-file-when-offline
http://stackoverflow.com/questions/14670638/webview-load-website-when-online-load-local-file-when-offline
2015 m. rugpjūčio 28 d., penktadienis
php image classes
https://github.com/claviska/SimpleImage php 5.3 + GD
http://imagine.readthedocs.org/en/latest/index.html php 5.3 GD/imagick
http://phpthumb.sourceforge.net/ php 4+/5 GD/imagick
imagick pamokos: http://www.phpro.org/tutorials/Imagick.html
http://imagine.readthedocs.org/en/latest/index.html php 5.3 GD/imagick
http://phpthumb.sourceforge.net/ php 4+/5 GD/imagick
imagick pamokos: http://www.phpro.org/tutorials/Imagick.html
PHP URL shortening functions
Integer konvertavimas.
Jigu tinka - ir _ simboliai
Jigu tinka - ir _ simboliai
function encode($number) {
return strtr(rtrim(base64_encode(pack('i', $number)), '='), '+/', '-_');
}
function decode($base64) {
$number = unpack('i', base64_decode(str_pad(strtr($base64, '-_', '+/'), strlen($base64) % 4, '=')));
return $number[1];
}
jeigu norima tik raidyno ir skaiciu
- function encode($val, $base=62, $chars='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') {
- // can't handle numbers larger than 2^31-1 = 2147483647
- $str = '';
- do {
- $i = $val % $base;
- $str = $chars[$i] . $str;
- $val = ($val - $i) / $base;
- } while($val > 0);
- return $str;
- }
- function decode($str, $base=62, $chars='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') {
- $val = 0;
- for($i = 0; $i < $len; ++$i) {
- }
- return $val;
- }
paprastam url konvertavimui
function base64url_encode($data) {
return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
}
function base64url_decode($data) {
return base64_decode(str_pad(strtr($data, '-_', '+/'), strlen($data) % 4, '=', STR_PAD_RIGHT));
}
return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
}
function base64url_decode($data) {
return base64_decode(str_pad(strtr($data, '-_', '+/'), strlen($data) % 4, '=', STR_PAD_RIGHT));
}
Užsisakykite:
Pranešimai (Atom)