vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Retrieving lastvisit, should be easy... (https://vborg.vbsupport.ru/showthread.php?t=37324)

mr e 04-12-2002 04:57 AM

Retrieving lastvisit, should be easy...
 
Ok this is my code

PHP Code:

$getuser=$DB_site->query("SELECT * FROM user WHERE userid=$bbuserinfo[userid]");

while (
$user=$DB_site->fetch_array($getuser)) {
$username=$user[username];
$userlastvisit=$user['lastvisit'];
$newposts="<a href=\"search.php?s=$session[sessionhash]&action=getnew\">View New Posts</a>";
$logout="<smallfont><a href=\"member.php?s=$session[sessionhash]&action=logout\">Log Out</a>";
$markallread="<a href=\"member.php?s=$session[sessionhash]&action=markread\">Mark All Forums Read</a>";
}

eval(
"\$welcometext .= \"".gettemplate('home_usercp')."\";"); 

But everytime I call $userlastvisit it says "1018586613" I have tried $user[lastvisit], $user[lastvisitdate], $user['lastvisit'], and $user['lastvisitdate']. I'm probably making this harder than it should be, but help please. :ogre:

Admin 04-12-2002 04:03 PM

First of all, use the query_first() method instead of query() and then fetch_array(), since you are only getting one row of data. :)

Anyway, what you get (that long number) is in Unix Timestamp, and needs to be converted. Use:
Code:

$userlastvisit = vbdate("FORMAT", $user['lastvisit']);
FORMAT is the format of the date / time, see the manual entry for date() for more info.

mr e 04-13-2002 01:13 AM

:D Thanx FireFly, that was MUCH easier than what I thought it would be. :bandit:

But about the query_first, if I use that I get an error in db_mysql about a bad argument, so I had to just use query.

Admin 04-13-2002 06:00 AM

If you use query_first() you don't need fetch_array(), because it does that internally.

So instead of:
Code:

$getuser=$DB_site->query("SELECT * FROM user WHERE userid=$bbuserinfo[userid]");

while ($user=$DB_site->fetch_array($getuser)) {
$username=$user[username];
$userlastvisit=$user['lastvisit'];
$newposts="<a href=\"search.php?s=$session[sessionhash]&action=getnew\">View New Posts</a>";
$logout="<smallfont><a href=\"member.php?s=$session[sessionhash]&action=logout\">Log Out</a>";
$markallread="<a href=\"member.php?s=$session[sessionhash]&action=markread\">Mark All Forums Read</a>";
}

You just use this:
Code:

$user=$DB_site->query_first("SELECT * FROM user WHERE userid=$bbuserinfo[userid]");

$username=$user[username];
$userlastvisit=$user['lastvisit'];
$newposts="<a href=\"search.php?s=$session[sessionhash]&action=getnew\">View New Posts</a>";
$logout="<smallfont><a href=\"member.php?s=$session[sessionhash]&action=logout\">Log Out</a>";
$markallread="<a href=\"member.php?s=$session[sessionhash]&action=markread\">Mark All Forums Read</a>";


mr e 04-13-2002 05:53 PM

Oh ok I got it now, sorry I'm still trying to learn all this coding.

jjj0923 04-15-2002 11:26 AM

Firefly - what a timely post.

Thanks for this information.

While we're on the subject, I was working over the weekend trying something along the same lines.

I have Photopost installed along with vbulletin and I want to pop-up a little javascript message or display a blinking "photo gallery" graphic if there have been new photos posted in the gallery since the users last visit.

The problem I was running into was selecting the photopost db in index.php. It would appear to get selected properly (since servername, username & password) are the same, but then I went to select data from the photpost db, I would get a message returned a string that said something like "Resource ID 27".

I'm fairly confident the select_db was working ok becuase if I did not reselect the Vbulletin db at the end of my code, vb would throw errors.

any ideas????

thanks if advance Firefly!

- jeff

Admin 04-15-2002 11:34 AM

Code:

$result = mysql_query_db(...);
$result isn't what you are looking for, you first need to fetch the row:
Code:

$row = mysql_fetch_array($result);
And then use $result['fieldName'].

jjj0923 04-15-2002 11:46 AM

cool - thanks!

now where do you want me to send contributions for that condo????

:) - jeff


All times are GMT. The time now is 10:04 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.00983 seconds
  • Memory Usage 1,732KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (5)bbcode_code_printable
  • (1)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (8)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete