Search
Search titles only
By:
Search titles only
By:
Log in
Register
Search
Search titles only
By:
Search titles only
By:
Menu
Install the app
Install
Forums
New posts
All threads
Latest threads
New posts
Trending threads
Trending
Search forums
What's new
New posts
New ads
New profile posts
Latest activity
Free Ads
Latest reviews
Search ads
Members
Current visitors
New profile posts
Search profile posts
Contact us
Latest ads
ඕනම රටකට සෙට් වෙන CV එකක්
ErMurazor
Updated:
Saturday at 9:50 AM
Hambantota
7 Acres Beachfront Land For Sell DownSouth , PerPerch Price 420 000
1024 Digital
Updated:
Wednesday at 11:57 AM
Baseus PI LITE INDOOR CAMERA
ErMurazor
Updated:
Oct 12, 2026
Ad icon
Colombo
Hard Disk For Sale
mazza
Updated:
Oct 10, 2026
land for sale
justasking
Updated:
Oct 10, 2026
Electronics
Vehicles
Property
Search
Reply to thread
Forums
General
ElaKiri Talk!
PHP Custom ID generate help ekak
Get the App
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Message
<blockquote data-quote="Lakshan-Seram" data-source="post: 26874022" data-attributes="member: 358904"><p>Hadissiye liwwe podi awl athi <img src="/styles/default/xenforo/smilies/default/rolleyes.gif" class="smilie" loading="lazy" alt=":rolleyes:" title="Rolleyes :rolleyes:" data-shortname=":rolleyes:" /></p><p></p><p>[CODE=php]<?php</p><p></p><p>/** Database **/</p><p>$server = 'localhost';</p><p>$user = 'root';</p><p>$pass = '';</p><p>$db = 'elakiri';</p><p>$table = 'elakiri';</p><p></p><p>/** Connection **/</p><p>$conn = new mysqli( $server, $user, $pass, $db );</p><p></p><p>/** If the connection is okay **/</p><p>if ( $conn->connect_error ) {</p><p> </p><p> die( 'Connection error: ' . $conn->connect_error );</p><p> </p><p>}</p><p></p><p>/** Start Id **/</p><p>$id = 1;</p><p></p><p>/** Gettings the last id **/</p><p>$query = 'SELECT user_id FROM ' . $table . ' ORDER BY id DESC LIMIT 1';</p><p>$result = $conn->query( $query );</p><p></p><p>if( $result->num_rows > 0 ) {</p><p> </p><p> /** The selected row in database **/</p><p> $row = $result->fetch_assoc();</p><p> </p><p> /** Extracting row **/</p><p> extract( $row );</p><p> </p><p> /** Getting the Id in the database **/</p><p> $id_last = substr( $user_id, -4 );</p><p> </p><p> /** Increment by 1 **/</p><p> $id = $id_last + 1;</p><p> </p><p>}</p><p></p><p>/** Last digits of the current year **/</p><p>$year = date( 'y' );</p><p></p><p>/** Format Id **/</p><p>$id_formatted = $year . sprintf( '%04d', $id );</p><p></p><p>/** Final Id **/</p><p>var_dump( $id_formatted ); // Do whatever with this :)</p><p></p><p>/** Colsing the connection **/</p><p>$conn->close();</p><p></p><p>?>[/CODE]</p><p></p><p>[CODE=sql]DROP TABLE IF EXISTS `elakiri`;</p><p>CREATE TABLE IF NOT EXISTS `elakiri` (</p><p> `id` int(11) NOT NULL AUTO_INCREMENT,</p><p> `user_id` int(6) NOT NULL,</p><p> PRIMARY KEY (`id`)</p><p>) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=latin1;</p><p></p><p>--</p><p>-- Dumping data for table `elakiri`</p><p>--</p><p></p><p>INSERT INTO `elakiri` (`id`, `user_id`) VALUES</p><p>(4, 210002),</p><p>(3, 210001);</p><p>COMMIT;[/CODE]</p><hr /><p>ah podi awlak una.. new year ekak kiyana kella mataka una lol</p><p>------ <span style="font-size: 10px">Post added on [DATETIME="UT"]1631540378[/DATETIME]</span></p><hr /><p>Update</p><p></p><p>[CODE=php]</p><p><?php</p><p></p><p>/** Database **/</p><p>$server = 'localhost';</p><p>$user = 'root';</p><p>$pass = '';</p><p>$db = 'elakiri';</p><p>$table = 'elakiri';</p><p></p><p>/** Connection **/</p><p>$conn = new mysqli( $server, $user, $pass, $db );</p><p></p><p>/** If the connection is okay **/</p><p>if ( $conn->connect_error ) {</p><p> </p><p> die( 'Connection error: ' . $conn->connect_error );</p><p> </p><p>}</p><p></p><p>/** Start Id **/</p><p>$id = 1;</p><p></p><p>/** Last digits of the current year **/</p><p>$year = date( 'y' );</p><p></p><p>/** Gettings the last id **/</p><p>$query = 'SELECT user_id FROM ' . $table . ' ORDER BY id DESC LIMIT 1';</p><p>$result = $conn->query( $query );</p><p></p><p>if( $result->num_rows > 0 ) {</p><p> </p><p> /** The selected row in database **/</p><p> $row = $result->fetch_assoc();</p><p> </p><p> /** Extracting row **/</p><p> extract( $row );</p><p> </p><p> /** Getting the Id in the database **/</p><p> $id_last = substr( $user_id, -4 );</p><p> </p><p> /** Getting the year in the database **/</p><p> $year_last = substr( $user_id, 0, 2 );</p><p> </p><p> if( $year == $year_last ) {</p><p> </p><p> /** Increment by 1 **/</p><p> $id = ( int ) $id_last + 1;</p><p> </p><p> }</p><p> </p><p>}</p><p></p><p>/** Format Id **/</p><p>$id_formatted = $year . sprintf( '%04d', $id );</p><p></p><p>/** Final Id **/</p><p>var_dump( ( int ) $id_formatted ); // Do whatever with this :)</p><p></p><p>/** Colsing the connection **/</p><p>$conn->close();</p><p></p><p>?></p><p>[/CODE]</p><p></p><p>[CODE=sql]DROP TABLE IF EXISTS `elakiri`;</p><p>CREATE TABLE IF NOT EXISTS `elakiri` (</p><p> `id` int(11) NOT NULL AUTO_INCREMENT,</p><p> `user_id` int(6) NOT NULL,</p><p> PRIMARY KEY (`id`)</p><p>) ENGINE=MyISAM AUTO_INCREMENT=6 DEFAULT CHARSET=latin1;</p><p></p><p>--</p><p>-- Dumping data for table `elakiri`</p><p>--</p><p></p><p>INSERT INTO `elakiri` (`id`, `user_id`) VALUES</p><p>(4, 200002),</p><p>(3, 200001),</p><p>(5, 210001);</p><p>COMMIT;[/CODE]</p><p>------ <span style="font-size: 10px">Post added on [DATETIME="UT"]1631540827[/DATETIME]</span></p></blockquote><p></p>
[QUOTE="Lakshan-Seram, post: 26874022, member: 358904"] Hadissiye liwwe podi awl athi :rolleyes: [CODE=php]<?php /** Database **/ $server = 'localhost'; $user = 'root'; $pass = ''; $db = 'elakiri'; $table = 'elakiri'; /** Connection **/ $conn = new mysqli( $server, $user, $pass, $db ); /** If the connection is okay **/ if ( $conn->connect_error ) { die( 'Connection error: ' . $conn->connect_error ); } /** Start Id **/ $id = 1; /** Gettings the last id **/ $query = 'SELECT user_id FROM ' . $table . ' ORDER BY id DESC LIMIT 1'; $result = $conn->query( $query ); if( $result->num_rows > 0 ) { /** The selected row in database **/ $row = $result->fetch_assoc(); /** Extracting row **/ extract( $row ); /** Getting the Id in the database **/ $id_last = substr( $user_id, -4 ); /** Increment by 1 **/ $id = $id_last + 1; } /** Last digits of the current year **/ $year = date( 'y' ); /** Format Id **/ $id_formatted = $year . sprintf( '%04d', $id ); /** Final Id **/ var_dump( $id_formatted ); // Do whatever with this :) /** Colsing the connection **/ $conn->close(); ?>[/CODE] [CODE=sql]DROP TABLE IF EXISTS `elakiri`; CREATE TABLE IF NOT EXISTS `elakiri` ( `id` int(11) NOT NULL AUTO_INCREMENT, `user_id` int(6) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=latin1; -- -- Dumping data for table `elakiri` -- INSERT INTO `elakiri` (`id`, `user_id`) VALUES (4, 210002), (3, 210001); COMMIT;[/CODE] [HR][/HR] ah podi awlak una.. new year ekak kiyana kella mataka una lol ------ [SIZE=2]Post added on [DATETIME="UT"]1631540378[/DATETIME][/SIZE] [HR][/HR] Update [CODE=php] <?php /** Database **/ $server = 'localhost'; $user = 'root'; $pass = ''; $db = 'elakiri'; $table = 'elakiri'; /** Connection **/ $conn = new mysqli( $server, $user, $pass, $db ); /** If the connection is okay **/ if ( $conn->connect_error ) { die( 'Connection error: ' . $conn->connect_error ); } /** Start Id **/ $id = 1; /** Last digits of the current year **/ $year = date( 'y' ); /** Gettings the last id **/ $query = 'SELECT user_id FROM ' . $table . ' ORDER BY id DESC LIMIT 1'; $result = $conn->query( $query ); if( $result->num_rows > 0 ) { /** The selected row in database **/ $row = $result->fetch_assoc(); /** Extracting row **/ extract( $row ); /** Getting the Id in the database **/ $id_last = substr( $user_id, -4 ); /** Getting the year in the database **/ $year_last = substr( $user_id, 0, 2 ); if( $year == $year_last ) { /** Increment by 1 **/ $id = ( int ) $id_last + 1; } } /** Format Id **/ $id_formatted = $year . sprintf( '%04d', $id ); /** Final Id **/ var_dump( ( int ) $id_formatted ); // Do whatever with this :) /** Colsing the connection **/ $conn->close(); ?> [/CODE] [CODE=sql]DROP TABLE IF EXISTS `elakiri`; CREATE TABLE IF NOT EXISTS `elakiri` ( `id` int(11) NOT NULL AUTO_INCREMENT, `user_id` int(6) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=6 DEFAULT CHARSET=latin1; -- -- Dumping data for table `elakiri` -- INSERT INTO `elakiri` (`id`, `user_id`) VALUES (4, 200002), (3, 200001), (5, 210001); COMMIT;[/CODE] ------ [SIZE=2]Post added on [DATETIME="UT"]1631540827[/DATETIME][/SIZE] [/QUOTE]
Insert quotes…
Verification
Asuwa dahayen wadi kalama keeyada?
Post reply
Top
Bottom