Jump to content
php.lv forumi

php kods kas izvelk pirmos 6 skaitljus!


Recommended Posts

Lieta tāda ka nezinu ka izvilkt pirmos 6 ciparus no 8ņām!


Ideja ir ID sistēma.

pirmie 6 cipari atbilst gadam, menesim un datumam.

Piem., 15091401 - 15 - gads, 09 - menesis, 14 - diena un 01 - dienas id.

vajadzētu kodu kas parbauda vai pirmie 6 cipari atbilst date("ymd"), ja atbilst true, ja ne, False.

Link to comment
Share on other sites



datetime::createfromformat('ymd', substr($id, 0, 6));

Nu man labi noredeeja substr(); :)


un re kas sanaaca! 

function makeID($target, $location) {
    global $db;
    $row = $db->getRow("SELECT ".$target." FROM ".$location." ORDER BY ID DESC LIMIT 1");
    if(substr($row->$target, 0, 6) == date("ymd")) {
        return $row->$target+1;
    } else {
        return date("ymd")."01";
Link to comment
Share on other sites

Esi padomājis par to, kas notiks, ja tev vienā dienā būs 100 ieraksti?





05100900 <---- nākamais datums.


un pēc tam tev visi nākamie ieraksti veidosies ar 


Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...