php - CodeIgniter get last username without primary id -


I have a problem getting the latest user name in my database. I do not have the database not auto_increment ID field Below is my code:

  public function _username_check ($ user_name) {$ this- & gt; Db- & gt; Select ('user_name'); $ This- & gt; Db- & gt; Like ('user_name', $ user_name); $ This- & gt; Db- & gt; Order_by ('USER_DATE'); $ Query = $ this- & gt; Db- & gt; Receive ('user'); If ($ query-> num_rows ()> 0) {$ row = $ query- & gt; Line (); $ Db_username = $ row- & gt; User name; Echo $ db_username; } Echo "if the function did not come"; }  

I am currently using community proof files for my projects, there is no auto increment ID field, so I check the final entry I'm using user_date.

By no means does this function go, am I doing something wrong here?

If the user wants to enter a user name, I will need to be able to return the user name and if the user wants to enter the user, then I have to be able to bring the user back.

Is this the right way to do this?

Any kind of spirits can help me on this? Thanks in advance for the help.

I suggest you to add an additional column in the user code With the date time field. By adding a date time field, you can find the latest user name, not changing existing DB relationships.

$ this-> Db- & gt; Select ('user_name'); $ This- & gt; Db- & gt; Like ('user_name', $ user_name); $ This- & gt; Db- & gt; Order_by ('USER_DATE', 'desc'); $ This- & gt; Db- & gt; Border (1); $ Query = $ this- & gt; Db- & gt; Receive ('user');

Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -