Newest User code

Discussion in 'Requests' started by Rupert Avery, Mar 19, 2012.

  1. Rupert Avery

    Rupert Avery New Member

    Joined:
    Nov 24, 2011
    Messages:
    157
    Likes Received:
    4
    Hey folks Just wondered how easy it would be to add a piece that updated who the Latest person to register was?
     
  2. Xeonn

    Xeonn New Member

    Joined:
    Dec 15, 2011
    Messages:
    372
    Likes Received:
    54
    In my opinion the code is like this:

    PHP:
    $query "SELECT nick FROM " $DBPrefix "users
                      ORDER BY reg_date DSC LIMIT 1
    $res = mysql_query($query);
    $system->check_mysql($res$query, __LINE__, __FILE__);
    than of course template vars
     
    Last edited: Mar 19, 2012
    Rupert Avery likes this.
  3. Rupert Avery

    Rupert Avery New Member

    Joined:
    Nov 24, 2011
    Messages:
    157
    Likes Received:
    4
    where would you stick that code? just where you want it to show?
     
  4. Xeonn

    Xeonn New Member

    Joined:
    Dec 15, 2011
    Messages:
    372
    Likes Received:
    54
    I don't know if the is no syntax error in this code, but you must select nick from table order by descending reg_date and limit it by 1 to show ( means last )
    than vars for show on page so it could be like this in php file :

    $query = "SELECT nick, country, reg_date FROM " . $DBPrefix . "users
    ORDER BY reg_date DSC LIMIT 1;
    $res = mysql_query($query);
    $system->check_mysql($res, $query, __LINE__, __FILE__);
    while ($row = mysql_fetch_assoc($res))
    {
    $template->assign_block_vars('lastuser', array(
    'ID' => $row['id'],
    'NICK' => $row['nick'],
    'COUNTRY' => $row['country'],
    'DATA_REG' => $row['reg_date']
    ));
    }

    than where you want to show you use in tpl file:
    <!-- BEGIN lastuser -->

    I think it should work if there is no syntax error
     
    Last edited: Mar 19, 2012
  5. Rupert Avery

    Rupert Avery New Member

    Joined:
    Nov 24, 2011
    Messages:
    157
    Likes Received:
    4
    Okay, so where do I put that code? and could it just include the Nickname and date of reg?

    I would like it to show under news on the right side...
     
  6. Xeonn

    Xeonn New Member

    Joined:
    Dec 15, 2011
    Messages:
    372
    Likes Received:
    54
    if on main site that it should be in index.php

    $query = "SELECT nick, reg_date FROM " . $DBPrefix . " users
    ORDER BY reg_date DSC LIMIT 1";
    $res = mysql_query($query);
    $system->check_mysql($res, $query, __LINE__, __FILE__);
    while ($row = mysql_fetch_assoc($res))
    {
    $template->assign_block_vars('lastuser', array(
    'NICK' => $row['nick'],
    'DATA_REG' => $row['reg_date']
    ));
    }


    and uder news in tpl <!-- BEGIN lastuser -->

    but pls check in editor if there is no syntax error
     
    Last edited: Mar 19, 2012
  7. Rupert Avery

    Rupert Avery New Member

    Joined:
    Nov 24, 2011
    Messages:
    157
    Likes Received:
    4
    there is a syntax error
     
  8. Xeonn

    Xeonn New Member

    Joined:
    Dec 15, 2011
    Messages:
    372
    Likes Received:
    54
    in home.tpl :

    <tr>
    <td class="your style">
    <ul>
    <!-- BEGIN lastuser -->
    <li>{NICK}</li>
    <li>{DATA_REG}</li>
    <!-- END lastuser -->
    </ul>
    </td></tr>

    in index.php :
    PHP:
    $query "SELECT nick, reg_date FROM " $DBPrefix "users ORDER BY reg_date DESC, reg_date DESC LIMIT 1";
    $res mysql_query($query);
    $system->check_mysql($res$query__LINE____FILE__);
    while (
    $row mysql_fetch_assoc($res))
    {
    $template->assign_block_vars('lastuser', array(
    'NICK' => $row['nick'],
    'DATA_REG' => $row['reg_date']
    ));
    }
     
  9. Rupert Avery

    Rupert Avery New Member

    Joined:
    Nov 24, 2011
    Messages:
    157
    Likes Received:
    4
    this works apart from one issue.. it doesnt show the person's name or date of reg its just blank :s
     
  10. Xeonn

    Xeonn New Member

    Joined:
    Dec 15, 2011
    Messages:
    372
    Likes Received:
    54
    in home.tpl :
    <!-- IF B_NEWS_BOX -->
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td class="titTable1">{L_282}
    </td>
    </tr>
    <tr>
    <td class="table1">
    <ul>
    <!-- BEGIN newsbox -->
    <li>{newsbox.DATE} - <a href="viewnew.php?id={newsbox.ID}">{newsbox.TITLE}</a></li>
    <!-- END newsbox -->
    </ul>
    </td>
    </tr>
    </table> <p />
    <!-- ENDIF -->

    <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td class="table1">
    <!-- BEGIN lastuser -->
    <ul>
    <li>{lastuser.NICK}</li>
    <li>{lastuser.DATA_REG}</li>
    <!-- END lastuser -->
    </ul>
    </td></tr>
    </table>

    i forgot this on red letter ,
    in index.php
    //last user
    $query = "SELECT nick, reg_date FROM " . $DBPrefix . "users ORDER BY reg_date DESC LIMIT 1";
    $res = mysql_query($query);
    $system->check_mysql($res, $query, __LINE__, __FILE__);
    while ($lastuser = mysql_fetch_assoc($res))
    {
    $template->assign_block_vars('lastuser', array(
    'NICK' => $lastuser['nick'],
    'DATA_REG' => FormatDate($lastuser['reg_date'])
    ));
    }
    paste just before
    include 'header.php';

    you can add links to user or auction of user in tpl <li>{lastuser.NICK} - <a href ....
     
    Last edited: Mar 19, 2012
  11. Xeonn

    Xeonn New Member

    Joined:
    Dec 15, 2011
    Messages:
    372
    Likes Received:
    54
  12. Rupert Avery

    Rupert Avery New Member

    Joined:
    Nov 24, 2011
    Messages:
    157
    Likes Received:
    4
    that works :) but i went and messed up my DB for reg dates everyone is now set to 0 :(

    I will remove seeing reg date because i have no quick way to update everyone's which is annoying

    ah rubbish i really have messed it up I think I will have to restore my DB to fix it but then I loose my latest members
    ARGH
     
  13. Xeonn

    Xeonn New Member

    Joined:
    Dec 15, 2011
    Messages:
    372
    Likes Received:
    54
    what did you do with your reg_date? :) we only read table not update them :)
     
  14. Rupert Avery

    Rupert Avery New Member

    Joined:
    Nov 24, 2011
    Messages:
    157
    Likes Received:
    4
    I changed the variable and i shouldnt of so i will have to restore it and contact the user and the people that have put up auctions... Luckily i wont loose too much
     
  15. Xeonn

    Xeonn New Member

    Joined:
    Dec 15, 2011
    Messages:
    372
    Likes Received:
    54
    When you want to add link to profile change in index.php

    //last user
    $query = "SELECT id, nick, reg_date FROM " . $DBPrefix . "users ORDER BY reg_date DESC LIMIT 1";
    $res = mysql_query($query);
    $system->check_mysql($res, $query, __LINE__, __FILE__);
    while ($lastuser = mysql_fetch_assoc($res))
    {
    $template->assign_block_vars('lastuser', array(
    'ID' => $lastuser['id'],
    'NICK' => $lastuser['nick'],
    'DATA_REG' => FormatDate($lastuser['reg_date'])
    ));
    }

    in home.tpl change:
    <!-- BEGIN lastuser -->
    <ul>
    <li><a href="profile.php?id={lastuser.ID}">{lastuser.NICK}</a></li>

    you must be logged in to make a link work well , I'm trying to do it even if user is not logged , any suggestions?
     
    Rupert Avery likes this.
  16. Rupert Avery

    Rupert Avery New Member

    Joined:
    Nov 24, 2011
    Messages:
    157
    Likes Received:
    4
    thank you thank you! I have had to make some changes to the code because of my little DB error which i intend to fix when i can.. but at the moment it looks for User ID as the order.
    I really need to be able to fix my DB and re import the users section lol
    but thank you this should help the link thing!
     
  17. Rupert Avery

    Rupert Avery New Member

    Joined:
    Nov 24, 2011
    Messages:
    157
    Likes Received:
    4
    Its okay i have figured why.
    you put in to go to the id not the profile and because i am logged in as me it just puts me to my profile.. I think
     
    Last edited: Mar 19, 2012
  18. Rupert Avery

    Rupert Avery New Member

    Joined:
    Nov 24, 2011
    Messages:
    157
    Likes Received:
    4
    I managed to get access to a backup that had all the codes for user Registration dates so I am manually restoring!

    I think as my first kind of mod I will Adapt this a little and turn it into "last Active Users"

    I realise it wont take much I think but wish me luck :)
     
  19. Rupert Avery

    Rupert Avery New Member

    Joined:
    Nov 24, 2011
    Messages:
    157
    Likes Received:
    4
    Hiya again.

    Any luck with making the links work?

    I Have tried to make a new heading showing the last active users.

    The problem is the users show under the same heading as the newest members..... I managed to insert the header.

    Please if you can have a look

    the code I used for it was

    In index.php under the last user code

    Code:
    //last login
    $query = "SELECT nick, lastlogin FROM " . $DBPrefix . "users ORDER BY lastlogin DESC LIMIT 3";
    $res = mysql_query($query);
    $system->check_mysql($res, $query, __LINE__, __FILE__);
    while ($lastlogin = mysql_fetch_assoc($res))
    {
    $template->assign_block_vars('lastuser', array(
    'NICK' => $lastlogin['nick'],
    'LASTLOGIN' => FormatDate($lastlogin['lastlogin'])
    ));
    }
    and in home.tpl under the categories list i used

    Code:
    <br>
        <div class="titTable1 rounded-right">Recently Active Users
    </div>
    <!-- BEGIN lastlogin -->
    <ul>
    <li><b>{lastlogin.NICK}<br>{lastuser.LASTLOGIN}</br></li>
    </ul>
    </div>
    </div>
    <!-- END lastlogin -->
    have a look at my site

    you will see the 6 names under Newest Members: 3 of them are correct the other 3 are meant for the left side.

    can you tell me where I have gone wrong?
     
  20. Xeonn

    Xeonn New Member

    Joined:
    Dec 15, 2011
    Messages:
    372
    Likes Received:
    54
    you have in index.php
    $template->assign_block_vars('lastuser', array(

    change to :
    $template->assign_block_vars('lastlogin', array(

    in tpl you have:
    <li><b>{lastlogin.NICK}<br>{lastuser.LASTLOGIN}</br></li>

    change to:
    <li><b>{lastlogin.NICK}<br>{lastlogin.LASTLOGIN}</br></li>
    :D is an copy-paste mistake , I had it also not once :D

    pls note for future that in red belove should be the same:
    while ($lastlogin = mysql_fetch_assoc($res)) { $template->assign_block_vars('lastuser', array(

    so than int tpl file you use this what you want to show , in your site you have
    3 nick from lastuser and 3 from lastlogin :) that why you have an error :)
     
    Last edited: Mar 20, 2012
    Rupert Avery likes this.

Share This Page